Search code examples
luazerobranelua-5.1lua-5.3

Call to String.pack returns pack method not found


I'm running Zerobrane 1.8 and LUA 5.3. However, in the interpreter the string function does not have "pack()" method/sub-function, i.e.,

  print(string.pack("<I4",9))

returns the error: "pack method is nil."

I've tried this in other online version of lua interpreters but got the same problem. Yet, the reference manual

https://www.lua.org/manual/5.3/manual.html#pdf-string.pack clearly shows that this function should exist. What am I missing here?


Solution

  • As pointed out in the comments, the Local console interpreter uses the same Lua version as the one that runs the IDE, which is Lua 5.1 by default. Switching the interpreter in the IDE only affects running and debugging scripts. A simple workaround to get Lua 5.3 interpreter in the console is to start a debugging session using Lua 5.3 interpreter, which will allow to run Lua 5.3 commands in the (Remote) console. There is also a related ticket, which you may want to monitor or contribute to.