From: Julien Hamaide <julien.hamaide@10tacle.be>
Reply-To: Lua list <lua@bazar2.conectiva.com.br>
To: Lua list <lua@bazar2.conectiva.com.br>
Subject: Re: Calling a member function from C
Date: Fri, 18 Aug 2006 13:46:29 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
When you call IWindow:new(100, "foo")
actually, IWindow.new(IWindow, 100, "foo") is executed.
: is a syntactic sugar for C++ "thiscall" type. Your object will always
be the first argument ( named self )
so just do this in your code to have the exact equivalent of lua code
lua_getglobal(L, "IWindow");
lua_getfield(L, -1, "new");
lua_pushvalue( L, -2 ); //copy IWindow on top of the stack
lua_pushnumber(L, 100);
lua_pushstring(L, "foo");
if (lua_pcall(L, 2, 1, 0) != 0)
{
printf("\n%s", lua_tostring(L, -1));
}
Julien
Lyte _ wrote:
> Hello!
>
> I want to call a lua member function from C, and I can not get it to
> work. This is how I do it now.
>
> lua_getglobal(L, "IWindow");
> lua_getfield(L, -1, "new");
> lua_pushnumber(L, 100);
> lua_pushstring(L, "foo");
> if (lua_pcall(L, 2, 1, 0) != 0)
> {
> printf("\n%s", lua_tostring(L, -1));
> }
>
> I have a class in lua called IWindow, and it has a member function
> called new. So I want to do IWindow:new(100,"foo") basicly. But for some
> strange reason, when I arrive in my function, the first parameter is
> "foo" and the second parameter is nil. So where has the number (100)
> gone? I'm sure the error is just something small, but I do not
> understand what it is...
>
> - Lyte
>
> _________________________________________________________________
> Messenger direkt i din 3-mobil!
> http://msn.microsoft.se/adstat/msnstats/sweden/redirect.asp?msnid=1460
>
>
>
- --
- --
Julien Hamaide
Engineering Coach
10Tacle Studios Belgium / Elsewhere Entertainment
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFE5aiV/nbvGx8yYLARAnIiAJ4xNH5iWpx709bjUHRYJhyLJJa6MACgpaMV
JGn30hEiigsf9YkWr9tRjSs=
=6AW6
-----END PGP SIGNATURE-----