I have a small Lua script:
function g () print( AUp); end
From C Download the script, add a variable called AUp and let it run several hundred times.
for( i=0; i<2000; i++) { num= i; lua_pushnumber( L, i); lua_setglobal( L, "AUp"); lua_getglobal( L, "g"); if (lua_call( L, 0, 0) != 0) printf( "%s", lua_tostring(L, -1)); }
Print output is 0, always. If I put (i + 1) in, the output is always 1. I cannot change the value of AUp. The value remains unchanged, as in the very first call to lua_pushnumner and lua_setglobal.
What's wrong? The function should be called again and again, but the AUp value may change, so I have to update it before calling lua_call .
source share