I am trying to write a function that produces a string of a fixed length. There are two cases I think I need to consider:

1. The string is too long and must be cropped
2. The string is too short and must be padded with whitespace

To do this, I have written the following:

```lua
foo = "testtesttesttest"
bar = "test"

function fixed_width_a(s)
  return string.format("%-6s", string.sub(s, 1, 6))
end

print(fixed_width_a(foo))
print(fixed_width_a(bar))

-- testte
-- test__ (Using underscores to denote spaces)

```

While I don't know if this is the best way, it works. Great!

Now, I'd like to be able to specify the width of the string as a parameter. For example,

```lua
function fixed_width_b(s, w)
  w = w or 6
  return string.format("%-ws", string.sub(s, 1, w))
end

```

Of course, this naive attempt doesn't work because "%-ws" isn't parsed correctly. Another attempt might be to specify,

```lua
string.format("%-{%d}s", w, string.sub(s, 1, w))

```

but obviously this makes no sense either.

Question: how do I specify formatting options using a variable in `string.format`?