Using the functions of standard Lua modules constantly returns Runtime error. Code example:
//... char script[] = "io.write(\"Hello!\n\")"; printf("%d\n", luaL_loadbuffer(L, script, strlen(script), NULL)); printf("%d\n", lua_pcall(L, 0, 0, 0)); //...
The screen displays:
0 2
According to the definition of errors in lua.h, the number 2 corresponds to LUA_ERRRUN.
In this case, the same line works in the terminal:
$ lua Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio > io.write("Hello!\n"); Hello!
Using standard lua elements does not result in an error:
//... char script[] = "print(\"Hello!\")"; printf("%d\n", luaL_loadbuffer(L, script, strlen(script), NULL)); printf("%d\n", lua_pcall(L, 0, 0, 0)); //...
Displays:
0 Hello! 0
How to use such functions? Thank!