1

string.format("%q", foo_str) will format a string to add the appropriate escape chars to make it safe to read back into the Lua interpreter. How can I best use this function to format a Lua_Buffer from the C-API? More generally, how can I access the string.* functions from the C-API? I could use lua_pcall("string.format", ...), but curious if there is a more direct way.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Paul
  • 2,973
  • 6
  • 31
  • 40

1 Answers1

2

The format function is defined as static in the lstrlib.c module, so AFAIK the only way to get to it is through the string table.

I suppose you could look at addquoted in lstrlib.c and adjust it for your use, but probably easier to just call string.format.

Mud
  • 28,277
  • 11
  • 59
  • 92