Sign in to follow this  

LUA techniques

This topic is 3593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, as a virtual environment researcher, I have done some tests with LUA scripting (using luabind for the bindings to our engine) to implement the logic of our virtual worlds. I am now at the point that we need more advanced functionality to cope with more complex worlds. I would appreciate it if someone could help us with one of the following questions: - We use a lot of factory classes to instantiate certain types of objects. Classes handling these objects can cast to their specific type to do specific stuff. How is this best handled in LUA/luabind? In (pseudo-) C++ for example, we do
MyObject *pObject = (MyObject *) ObjectManager::createObject("MyObject");
pObject->doSpecificStuff();
I want to be able to do the object-type-specific functions in LUA too, so I need casting or a way to add functionality to LUA objects at runtime. Is either one possible? Or should I start thinking in a whole different way? - I want to have scripts that belong to a certain object. A zone trigger object for example, should have a script with a onCreated and onDestroyed function (common for all objects) and a onEntered, onInside and onLeft functions (specific for trigger objects). The problem is that I don't find a way to keep the function names local to a script. Should all objects have their own namespace? Should the functions be in a LUA table and added to some event manager? Thanks already! Greetz, JeDi

Share this post


Link to post
Share on other sites
It's Lua not LUA.
I'm left puzzled as to where this "LUA" came from; it would be like everyone saying PYTHON suddenly....

Anyways;

1) This is pretty simple really;
- expose the class to Lua via LuaBind (see docs)
- create an instance of that object
- call instance:doSpecificStuff()

You won't even have to cast as things should just resolve themselves.. probably.

2) Tables are Lua's natural method of encapsulation of data types, so you should be using those as required. You can do OO things with it as well.

Specific examples are hard to give, but what you want to do is possible, just going to require some reading around the Lua docs.

Share this post


Link to post
Share on other sites
phantom: I like PYTHON but really it is an ivory tower academic thing to full cap language names.

I haven't done much with Lua but it seems like to do that you muck around with the objects tables as that is the behind the scenes data structure.

Share this post


Link to post
Share on other sites
First of all, we don't use the constructors of our concrete object classes explicitly, but through a manager and factory classes. I don't want Lua to do any memory allocation, we handle that in platform-specific classes. So when we create an object of a certain type, we always receive a pointer to the base Object class.

In a lot of cases, the object is already constructed before scripting kicks in anyway (scene loading etc.). So this is not per se for the creation of objects, but for querying them, f.e.

ball = scene:getObject("myball")
ball:startRolling()


The scene object doesn't know a thing about the different types of objects it handles, so in the C++ side I can only return an Object pointer through the getObject function.

I create my bindings through luabind, so I already have bindings for my Scene class (createObject, getObject, ...) and my Object class. I just don't know how to expose the type-specific functions.

Share this post


Link to post
Share on other sites

This topic is 3593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this