in my C file I call luaL_dostring like this:
luaL_dostring(L, "return 'somestring'");
How do I read this return value in C after this line?
Thanks.
Edit: Thanks for the help.
I'd like to add that to remove the element after retrieving it, you use:
lua_pop(L, 1);
The value is left on the Lua stack. In order to retrieve the value, use one of the lua_toXXXX
functions, with -1 as the index argument (-1 refers to the top of the stack). Alternatively, use lua_gettop()
to get the size of the stack.
In your case, use this:
luaL_dostring(L, "return 'somestring'");
const char * str = lua_tostring(L, -1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With