lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


	Hi Anders

On Fri, 14 Dec 2007, Anders Eriksson wrote:

> Hi all.
> 
> I try to use lua to make our render engine more generel.
> 
> I have made following simple script but can't call the functions!
> 
> 
> -- XXX configuration file.
> 
> RenderEngine = {
> };
> 
> Configuration = {
> width = 1280,
> height = 1024,
> fullscreen = 1
> };
> 
> -- Called before render engine is initialized
> 
> function RenderEngine:Initialize()
> return 1;
> end
> 
> -- Called after render engine is Shutdown
> 
> function RenderEngine:ShutDown()
> return 1;
> end
> 
> And my code for call Initialize looks like this.
> 
> lua_State *L = lua_open();
> luaL_openlibs(L);
> luaL_dofile(L, "../Scripts/initialize.lua");
> //luaL_loadfile(L, "../Scripts/initialize.lua");
> //lua_pcall(L,0,0,0);
> lua_getglobal(L, "Configuration");
> lua_pushstring(L, "width");
> lua_gettable(L, -2);
> int w = (int) lua_tonumber(L, -1);
> lua_pop(L, 1);
> lua_pushstring(L, "height");
> lua_gettable(L, -2);
> int h = (int) lua_tonumber(L, -1);
> lua_pop(L, 1);
	You forgot to pop the `Configuration' table from the stack.
It was intentional?

> lua_getglobal(L, "RenderEngine");
> lua_pushstring(L, "Initialize");
> lua_gettable(L, -1);
                  ^^
	I think this index might be -2, don't you?

> lua_insert(L, 1);
	I didn't understand what you mean with the above line...
You could push the "self" with `lua_pushvalue(L, -2);'

> lua_pcall(L, 0, 1, 0);
> int bOK = (int)lua_tointeger(L, -1);
> lua_pop(L, 1);
> 
> lua_close(L);
> 
> Can you see what I'm doing wrong ?

	I am not sure but I think the problem is in the stack...

	Regards,
		Tomás