Lua in C++

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua in C++

cougar
Hello,

I have a C++ class, which wraps the lua_state. Some of the class 
member functions are registered as lua functions, so they need to 
be static members. But what if I need to call non-static function 
from a static one? The only thing I have is the lua_state, I have 
no reference to the original object. Is there some easy way of 
storing my custom pointer within the lua_state or is there some 
other solution to this problem?

I'm sorry if this is a stupid question. I'm a lua newbie.

Thanks.


Cougar










--------------------
Jen GEnius vládne svým penězům bez omezení! http://user.centrum.cz/redir.php?url=http://www.genius.cz




Reply | Threaded
Open this post in threaded view
|

Re: Lua in C++

Daniel Silverstone
On Tue, Apr 16, 2002 at 03:46:41PM +0200, [hidden email] wrote:
> no reference to the original object. Is there some easy way of 
> storing my custom pointer within the lua_state or is there some 
> other solution to this problem?

One possibility is to use a userdata to store a pointer to your C++ class
instance, and then ensure that the userdata is passed to each of those
static functions (by using closures -- look at push_cclosure in your manual)

> I'm sorry if this is a stupid question. I'm a lua newbie.

We all were newbies once :)

D.

-- 
Daniel Silverstone                               http://www.digital-scurf.org/
Hostmaster, Webmaster, and Chief Code Wibbler          Digital-Scurf Unlimited
GPG Public key available from keyring.debian.org               KeyId: 20687895
You will soon forget this.

Reply | Threaded
Open this post in threaded view
|

Re: Lua in C++

Daniel Silverstone
On Tue, Apr 16, 2002 at 03:10:57PM +0100, Daniel Silverstone wrote:
> static functions (by using closures -- look at push_cclosure in your manual)

Sorry, misleading.

try lua_pushcclosure

I'm awake today

D.

-- 
Daniel Silverstone                               http://www.digital-scurf.org/
Hostmaster, Webmaster, and Chief Code Wibbler          Digital-Scurf Unlimited
GPG Public key available from keyring.debian.org               KeyId: 20687895
Your domestic life may be harmonious.

Reply | Threaded
Open this post in threaded view
|

Re: Lua in C++

James Hearn
In reply to this post by cougar
What I have done in the past is store the lua_state pointer as a userdata
inside the lua_state itself. Kind of ugly, but it was extremely
effective....

--James Hearn