lua-users home
lua-l archive

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


Title: Re: Exposing class instances as globals

Woops, spoke too soon.  Solved!  All I needed was a setglobal call in the right place.

Looking through the archives, I've seen several people looking for tips on how to expose classes to Lua.  I've attached an example bit of code I created while learning the Lua API that might be of help to others.

The code shows how to expose a class as creatable (and garbage collectable) from Lua, and how to expose an instance of an already instanciated class.  Be forewarned, this code was written in one pass and doesn't follow any real design pattern.

Thanks,
Brian

--- In lua-l@y..., Brian Smith <Brian.Smith@R...> wrote:
> I've been playing around with Lua a bit, and I've been able to expose my
> classes to Lua as tables.  However, I'm not sure how I can create an
> instance of a class in C++, and expose this instance to Lua as a global.  I
> can register the instance functions, but I don't know how to associate a
> name with the functions.
>
> Any tips?  I could perhaps expose a function that works like Luna's
> constructor, registering an existing instance's functions, but this seems
> less than optimal.
>
> Thanks,
> Brian

 

Attachment: testlua01.cpp
Description: Binary data