lua-users home
lua-l archive

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


At 23:40 23/09/2003 +0100, you wrote:
[..]
  function instance:debug()
        print("pos :"..self.Pos)
  end
[...]
and then do the following

        lua_getglobal(m_LuaVM, "myscript");
        if(lua_istable(m_LuaVM,-1)) {
                lua_pushstring(m_LuaVM,"debug");
                lua_gettable(m_LuaVM,-2);
                if(lua_isfunction(m_LuaVM,-1))
                        lua_call(m_LuaVM, 0, 0);
                else
                        lua_pop(m_LuaVM,1);
        }

now this actually works if I don't reference self.Pos and will print the string. but if I reference anything that

I think the problem is that you're not passing 'self' to the function.. when you call a function from lua using the colon, it's like calling it with self, for example 'object:method()' is actually 'object.method(object)'. So when using the C API, you need to do this by hand. You can probably do a 'lua_insert(ls, -2)', to swap the function with the table, and then 'lua_call(ls, 1, 0)', because you're actually sending 1 parameter ('self').

bye..


Ariel.
http://Anime.com.ar
snm