aboutsummaryrefslogtreecommitdiff
path: root/src/shared/lua_api
diff options
context:
space:
mode:
authorAlexander Pickering <alex@cogarr.net>2018-06-23 06:52:55 -0600
committerAlexander Pickering <alex@cogarr.net>2018-06-23 06:52:55 -0600
commite6faff1394864a1fe0d517584d1c104997dff39f (patch)
treed7956fc8aabef903f354578d69d4d7fdf64ec928 /src/shared/lua_api
parent1aaa348ac080c97c0aeb0a02146ae26b74add5a1 (diff)
parent9fa5dcc9310a8c6ff8c77a47a86303f7b950dcf3 (diff)
downloadbrokengine-e6faff1394864a1fe0d517584d1c104997dff39f.tar.gz
brokengine-e6faff1394864a1fe0d517584d1c104997dff39f.tar.bz2
brokengine-e6faff1394864a1fe0d517584d1c104997dff39f.zip
Merge branch 'master' of ssh://cogarr.net:43/home/git/brokengine
Diffstat (limited to 'src/shared/lua_api')
-rw-r--r--src/shared/lua_api/common.c37
-rw-r--r--src/shared/lua_api/common.h3
-rw-r--r--src/shared/lua_api/phys/bphysbox.cpp22
3 files changed, 51 insertions, 11 deletions
diff --git a/src/shared/lua_api/common.c b/src/shared/lua_api/common.c
index 9a8baca..2eeee11 100644
--- a/src/shared/lua_api/common.c
+++ b/src/shared/lua_api/common.c
@@ -153,6 +153,43 @@ int popvector3d(lua_State* L,double* a,double* b,double* c){
return 0;
}
+int popvector4d(lua_State* L, double *a, double *b, double *c, double *d){
+ lua_pushinteger(L,1);//{a,b,c,d},1
+ lua_gettable(L,-2);//{a,b,c,d},a
+ *a = lua_tonumber(L,-1);//{a,b,c,d},a
+ lua_pop(L,1);//{a,b,c,d}
+
+ lua_pushinteger(L,2);
+ lua_gettable(L,-2);
+ *b = lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ lua_pushinteger(L,3);
+ lua_gettable(L,-2);
+ *c = lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ lua_pushinteger(L,4);
+ lua_gettable(L,-2);
+ *d = lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ lua_pop(L,1);
+ return 0;
+}
+
+//{{sx,sy},{ex,ey}}
+int poprecti(lua_State* L, long *sx, long *sy, long *ex, long *ey){
+ lua_pushnumber(L,1);
+ lua_gettable(L,-2);
+ popvector2i(L,sx,sy);
+ lua_pushnumber(L,2);
+ lua_gettable(L,-2);
+ popvector2i(L,ex,ey);
+ lua_pop(L,1);
+ return 0;
+}
+
int popvector2i(lua_State* L, long* a, long* b){
lua_pushinteger(L,1);
lua_gettable(L,-2);
diff --git a/src/shared/lua_api/common.h b/src/shared/lua_api/common.h
index c2e067d..6086065 100644
--- a/src/shared/lua_api/common.h
+++ b/src/shared/lua_api/common.h
@@ -12,6 +12,9 @@ int pushvector3d(lua_State*,double,double,double);
int pushvector2i(lua_State*,long,long);
int popvector4i(lua_State*,long*,long*,long*,long*);
+int popvector4d(lua_State*,double*,double*,double*,double*);
int popvector3i(lua_State*,long*,long*,long*);
int popvector3d(lua_State*,double*,double*,double*);
int popvector2i(lua_State*,long*,long*);
+
+int poprecti(lua_State* L,long*,long*,long*,long*);
diff --git a/src/shared/lua_api/phys/bphysbox.cpp b/src/shared/lua_api/phys/bphysbox.cpp
index 78f1c45..0fe9f72 100644
--- a/src/shared/lua_api/phys/bphysbox.cpp
+++ b/src/shared/lua_api/phys/bphysbox.cpp
@@ -34,14 +34,14 @@ void makenewbphysbox(lua_State* L){
mass = lua_tonumber(L,-1);//{v3_size},{v3_origin},mass
lua_pop(L,1);//{v3_size},{v3_origin}
- printf("Got mass: %f\n",mass);
+ //printf("Got mass: %f\n",mass);
popvector3d(L,&px,&py,&pz);//{v3_size}
- printf("Got position: (%f,%f,%f)\n",px,py,pz);
+ //printf("Got position: (%f,%f,%f)\n",px,py,pz);
popvector3d(L,&sx,&sy,&sz);//
btVector3 vshape = btVector3(sx * 0.5f, sy * 0.5f, sz * 0.5f);
- printf("Got size: (%f,%f,%f)\n",sx,sy,sz);
+ //printf("Got size: (%f,%f,%f)\n",sx,sy,sz);
btVector3 pos = btVector3(px,py,pz);
// Set the initial position of the object
@@ -52,12 +52,12 @@ void makenewbphysbox(lua_State* L){
// Give it a default MotionState
btDefaultMotionState* motionstate = new btDefaultMotionState(transform);
if(!motionstate){
- printf("No motionstate\n");
+ //printf("No motionstate\n");
}
// Create the shape
btCollisionShape* shape = new btBoxShape(vshape);
if(!shape){
- printf("no shape\n");
+ //printf("no shape\n");
}
// Add mass
@@ -67,12 +67,12 @@ void makenewbphysbox(lua_State* L){
// Create the rigid body object
btRigidBody* rigidbody = new btRigidBody(mass, motionstate, shape, localinertia);
if(!rigidbody){
- printf("No rigidbody\n");
+ //printf("No rigidbody\n");
}
// Add it to the world
World->addRigidBody(rigidbody);
- printf("Added rigid body to world: %p\n",World);
+ //printf("Added rigid body to world: %p\n",World);
Objects.push_back(rigidbody);
lua_pushlightuserdata(L,rigidbody);//ud_rigidbody
@@ -80,7 +80,7 @@ void makenewbphysbox(lua_State* L){
// phys.newphysbox(vector3 size, vector3 origin, double mass)
int newbphysbox(lua_State* L){
- printf("Createing bphysbox!\n");
+ //printf("Createing bphysbox!\n");
//Create it's lua representation
makenewbphysbox(L);//ud_btRigidBody
btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);
@@ -98,7 +98,7 @@ int newbphysbox(lua_State* L){
//{phys.physbox}:delete()
static int delbphysbox(lua_State* L){//self
- printf("Attempting to delete physbox\n");
+ //printf("Attempting to delete physbox\n");
lua_getfield(L,-1,"rigidbody");//self,ud_rigidbody
btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);//self,ud_rigidbody
delete r->getCollisionShape();
@@ -130,7 +130,7 @@ static int bphyssetpos(lua_State *L){//self,{v3 pos}
// {v3 pos} :: physbox:getpos()
static int bphysgetpos(lua_State *L){//self
- printf("Physics box set pos called\n");
+ //printf("Physics box set pos called\n");
lua_getfield(L,-1,"rigidbody");//self,ud_rigidbody
btRigidBody* i = (btRigidBody*)lua_touserdata(L,-1);//self,ud_rigidbody
btTransform bt = i->getWorldTransform();
@@ -149,7 +149,7 @@ static const luaL_reg bphysbox_m[] = {
};
void bphysbox_register(lua_State* L){//
- printf("Registered bphysbox\n");
+ //printf("Registered bphysbox\n");
luaL_newmetatable(L, "phys.physbox");//{phys.physbox}
lua_newtable(L);//{phys.physbox},{}