lua-users home
lua-l archive

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


Jose Marin wrote:

Hi.

What´s the fastest way of mapping a C++ object (or C
struct) to Lua?


In C++
class NPC{
int health;
vector3 position;
// other attributes

void Move();
// other methods
};


In LUA

enemy1.health = 100
enemy1.Move()



If is there some way of map fast a C struct to a LUA
variable, this will be enough.

Note:
I wont use tolua, great tool, but I want to learn how
to do this myself
the fastest way is to use toLua or someother code generator or template such as Luna if you are doing C++.

Now if you want to do it by hand that is not the fastest way by a long shot. I did one by hand just to know how it works. Then I use the Luna template or something else automated, doing it by hand is tedious at best and error prone at worst.

There is pleny of documentation on the wiki on how to do this by hand.