lua-users home
lua-l archive

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


I am currently interfacing LUA with my game engine (C++) and the process is going rather smoothly but i've come across some issues I can't tackle all by myself :)

On the engine side, all objects share a common base class called Object which has a reflection system allowing to browse/access/invoke object fields and members at runtime (just like the C# or Java reflection system).

I want to manipulate these objects via Lua in a C++/OOP fashion. I managed to dereference sub objects by overloading the __index of my Object metatable and even call objects methods by overloading __call. These two hooks are very simple since they only need to query the reflection system for the right object field or method and return a pointer on an object via a lightuserdata or a closure on the needed method.

But when it come to assignments, I can't get some simple syntax :

	class Object
		String * ToString();
		Object * Parse( String * str );

	class Vector : public Object
		Float X;
		Float Y;
		Float SetNull();

	-- I want to write code like this
	v = new( "Vector" );
	v.x = 0.2;	-- for now, i must write: 	v.x:Parse( CreateString( "0.2" ) );
	v.y = 1.5;	-- for now, i must write: 	v.y:Parse( CreateString( "1.5" ) );

-- i need to hook to the assignment operation in order to correctly set v.x.

So basically what I want is a way to convert some lua values to a custom format when stumbling across code like "EngineObjectRef = LuaValue". Is this possible or do I need to work my integration differently ?

Many thanks in advance.

-Marc Fascia

Découvrez Windows Live Messenger : le futur de MSN Messenger !