I have a Lua script which is calling a C function. Currently this function is returning nothing. I want to change this function to return a string, so at the end of this function in C I will push the string into Stack. Inside the calling Lua script I need to get back the pushed string value.
C initialization and registration with Lua
void cliInitLua( void )
{
void* ud = NULL;
Task task;
// Create a new Lua state
L = lua_newstate(&luaAlloc, ud);
/* load various Lua libraries */
luaL_openlibs(L);
/*Register the function to be called from LUA script to execute commands*/
lua_register(L,"CliCmd",cli_handle_lua_commands);
//lua_close(L);
return;
}
This is my c Function to return a string:
static int cli_handle_lua_commands(lua_State *L){
...
...
char* str = ....; /*Char pointer to some string*/
lua_pushstring(L, str);
retun 1;
}
This is my Lua script
cliCmd("Anything here doesn't matter");
# I want to retreive the string str pushed in the c function.