• entries
135
130
• views
52717

# Almost checkout time.

126 views

I'm about to head home, I'll probably post something on-topic from there... basically have been doing more of the same, I keep meaning to go back to that UV bug, but I'm having fun with the other stuff I'm doing.

Why do I get all the stupid bugs?

** EDIT **
Look at the comments of this post for some LUA stuff =)

I was going to post in the other journal entry you had but oh well.

I got function calls from Lua to C working, but was just so perplexed by the amount of work required to get C++ classes into Lua that I just decided to drop it and continue on my Asteroids clone. I tried out Python and apparently it's really easy to bind in that. I still have to try out GameMonkey and Squirrel as well.

Any progress on your side of the factory? I'll upload the Lua class wrapper I made if you want it.

##### Link to comment
Well, yes and no... I was able to map C++ objects to LUA in the sense that in LUA you can write script like this:

local p = Vector3(1.1, 2.2, 9.3)
local y = Vector3(3.0, 3.1, 2.4)

local a = Vector3.add(y,p)

print("p: ", p:x(), p:y(), p:z())
print("y: ", y:x(), y:y(), y:z())
print("a: ", a:xyz())



What I was not able to do (even when I tried tolua) was map Vector3.add to C++'s:

Vector3 Vector3::Add(const Vector3& v)

instead, I ended up writing a more generic LUA library that looks like this:

class LUAVector3
{
DECLARE_SCRIPT(Vector3)

public:

static int Create(lua_State* L);

// Getters / Setters
static int x (lua_State *L);
static int y (lua_State *L);
static int z (lua_State *L);
static int xyz (lua_State *L);

// Operations
static int Add(lua_State* L);

// ....
};

{
Vector3* v1 = CheckType(L, 1);
Vector3* v2 = CheckType(L, 2);
Vector3* sum = Push(L);
*sum = *v1 + *v2;
return 1;
}



which is really just a C++ shell of C style classes... not what I really wanted, but it works. So, not great, not too bad.

So, if all I wanted to do was write libraries of things for LUA to do, then I can. The part that I still haven't figured out how I'm going to do is map events to script, but it's likely that it will involve C style functions in one way or another.

I can also bundle up some of this code if you're interested in checking it out.

## 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