Original Post
is there any chance to get the value of a variable that is defined in lua code after running it? like: - open *.lua file - running code - getting value of variable xy.
bool GetGlobalNumber( lua_State* p_lua, const char* p_name, lua_Number& number ){ // Put the value onto the stack. lua_getglobal( p_lua, p_name ); bool result = false; // Is the top of the stack a number? if ( lua_isnumber( p_lua, -1 ) ) { number = lua_tonumber( p_lua, -1 ); result = true; } // pop it off the stack now we're done lua_pop( p_lua, 1 ); return result;}void main(){ ... load script & execute lua_Number num; if ( GetGlobalNumber( p_lua, "xy", num ) ) { printf( "%f\n", num ); }}int lua_getInt(lua_State* L, const char* var) { int result; lua_getglobal(L,var); result =(int)lua_tonumber(L,-1); lua_pop(L,1); return result;}This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more