Advertisement

lua very simple task..but problem

Started by July 04, 2004 02:30 PM
-1 comments, last by FogGobbler 20 years, 4 months ago
Hi! All I want is to have a simple (THE most simplest script) like this: --my variable myvar = 10 When the script executes my c++ programm should get the value of my "myvar" variable and print it on the screen. This is what I´ve tried: int main ( int argc, char *argv[] ) { /* initialize Lua */ L = lua_open(); lua_baselibopen(L); lua_iolibopen(L); lua_strlibopen(L); lua_mathlibopen(L); open(L); // This is what I´ve found in one of the tutorials.. // doesn´t work lua_getglobal(L, "myvar"); myvar = (int)lua_tonumber(L, 1); lua_pop(L, 1); // Example: set a variable in c++ and print it out in lua // this works! lua_pushnumber(L, 10); lua_setglobal(L, "z"); lua_dofile(L, "test.lua"); /* output & cleanup Lua */ printf("MyVar: %i",myvar); // result: 0 lua_close(L); return 0; } Any suggestions ? thanks, oli

This topic is closed to new replies.

Advertisement