Re: Luabind and passing classes

Nigel Atkinson <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <1279762815.1444.12.camel@rincewind>
Hi Nathaniel,

Short answer: Yes.

If you bind a class using Luabind it can be passed to Lua functions as a
parameter.  When you bind a class you do not need to bind the class's
constructor.  Omitting the constructor prevents your Lua script from
being able to instantiate that particular class, however Lua can
otherwise use instances passed to it from C++.

I do this quite often with singleton classes.

Nigel Atkinson

On Wed, 2010-07-21 at 16:53 -0700, Nathaniel Lewis wrote:

> I was reading through some tutorials and I had a question unanswered.
> How do I pass a specific class to Lua?  I have a class that represents a
> world in my game engine and I need some way to talk with it from Lua.  I
> think LuaBind is the answer but I don't know.  I would never want to
> create the class from Lua.  Instead I would want to pass a reference to
> the one created on the c++ side to Lua and then call functions inside of
> it.  Is this possible with LuaBind?  Basically a simple script would
> look like this
> 
> -- called when map is loaded by engine --
> function Init (worldInstance) 
>     -- do stuff --
> end
> 
> -- called after every frame is rendered --
> Update = coroutine.wrap( function (worldInstance, timeSinceLastFrame)
>     while true do
> 	-- do stuff + call coroutine.yield() when waiting for things --
>     end
> end)
> 						Nathaniel
> 
> 
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.