2

I have a question: how do I make the lua_tostring function limit the amount of entries.

For example 8 characters limit:

poppy_name = "command"; // OK, within the limit;
poppy_name = "commander"; // Fail, Is out of range, show a message the permitted limit.

I searched I couldn't find anymore, is there a way to limit the lua_tostring?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Marcos Silva
  • 53
  • 1
  • 6

1 Answers1

3

Use lua_tolstring to obtain the string length, then use lua_error or luaL_error if the string is too long.

size_t arg_len;
lua_tolstring(L, 1, &arg_len);
if (arg_len > 8) return luaL_error(L, "argument too long");
catwell
  • 6,770
  • 1
  • 23
  • 21