lua-users home
lua-l archive

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


I would think this is what you want to do

 

int vec3add(lua_State *L) {

p=(vector3*)lua_newuserdata(L,sizeof(vector3));

vector3* v=(vector3*)lua_touserdata(L,1);

vector3* v2=(vector3*)lua_touserdata(L,2);

*p = *v + *v2

lua_getmetatable(L, 1); // ‘v’ should have one, right?

lua_setmetatable(L, -1); // in case you ever wanted to add something to ‘p’

return 1;

}

 

-----Original Message-----
From: Lava_Monkey [mailto:lava_monkey@optusnet.com.au]
Sent: Tuesday, May 13, 2003 7:25 AM
To: Multiple recipients of list
Subject: Re: on the topic of userdata

 

ah crap i answered my own question.. its always the way..

anyway here what i did, maybe its evil in some way please feel free to correct it..

 

int vec3add(lua_State *L) {

vector3* v=(vector3*)lua_touserdata(L,1);

vector3* v2=(vector3*)lua_touserdata(L,2);

*v+=*v2;

vector3* p;

p=(vector3*)lua_newuserdata(L,sizeof(vector3));

p=v;

lua_pushvalue(L, 1);

return 1;

}

 

it turns out that lua_newuserdata, pushes itself onto the stack anyway..

----- Original Message -----

To: Multiple recipients of list

Sent: Tuesday, May 13, 2003 11:58 PM

Subject: on the topic of userdata

 

ok this is what i want to do,

i've got a vector3 class similar to the vector3 tutorial in the example but using metatables of cause..

and what im trying to do is the __add for it, but im not sure what to return, or push onto the stack i should say.

 

heres what im doing in c atm..

 

int vec3add(lua_State *L) {

vector3* v=(vector3*)lua_touserdata(L,1);

vector3* v2=(vector3*)lua_touserdata(L,2);

*v+=*v2;

lua_pushlightuserdata(L, v);

return 1;

}

and in lua its just something like a=a+b;

anyway.. nothing happens. but this is all i could think of, does anyone have any ideas on what i should do or what im doing wrong.