aboutsummaryrefslogtreecommitdiff
path: root/src/shared/lua_api
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-12-26 00:57:52 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2017-12-26 00:57:52 -0500
commit35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940 (patch)
treed345f620b51ae1ad1d7923e572a6b07ed8731ee5 /src/shared/lua_api
parentcc12503339004bae2f945e7f7339fc845b2a194f (diff)
downloadbrokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.tar.gz
brokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.tar.bz2
brokengine-35b7c646fd7f80b64c1ef49b6d81f9df9bc1b940.zip
Major update
Diffstat (limited to 'src/shared/lua_api')
-rw-r--r--src/shared/lua_api/common.c47
-rw-r--r--src/shared/lua_api/common.h3
-rw-r--r--src/shared/lua_api/irr/cubenode.cpp6
-rw-r--r--src/shared/lua_api/irr/cubenode.hpp6
-rw-r--r--src/shared/lua_api/load_scene.cpp11
-rw-r--r--src/shared/lua_api/load_scene.hpp8
-rw-r--r--src/shared/lua_api/phys/bphysbox.cpp30
-rw-r--r--src/shared/lua_api/phys/bphysbox.hpp2
8 files changed, 89 insertions, 24 deletions
diff --git a/src/shared/lua_api/common.c b/src/shared/lua_api/common.c
index 140ece1..50eb850 100644
--- a/src/shared/lua_api/common.c
+++ b/src/shared/lua_api/common.c
@@ -39,19 +39,19 @@ void loadLLibs(lua_State* L){
int pushvector3i(lua_State* L,long a,long b,long c){
- lua_newtable(L);
+ lua_newtable(L);//{}
- lua_pushinteger(L,1);
- lua_pushinteger(L,a);
- lua_settable(L,-3);
+ lua_pushinteger(L,1);//{},1
+ lua_pushinteger(L,a);//{},1,a
+ lua_settable(L,-3);//{}
- lua_pushinteger(L,2);
- lua_pushinteger(L,b);
- lua_settable(L,-3);
+ lua_pushinteger(L,2);//{},2
+ lua_pushinteger(L,b);//{},2,b
+ lua_settable(L,-3);//{}
- lua_pushinteger(L,3);
- lua_pushinteger(L,c);
- lua_settable(L,-3);
+ lua_pushinteger(L,3);//{},3
+ lua_pushinteger(L,c);//{},3,c
+ lua_settable(L,-3);//{}
return 1;
}
@@ -72,6 +72,19 @@ int pushvector3d(lua_State* L,double a,double b,double c){
return 1;
}
+int pushvector2i(lua_State* L, long a, long b){
+ lua_newtable(L);
+
+ lua_pushinteger(L,1);
+ lua_pushinteger(L,a);
+ lua_settable(L,-3);
+
+ lua_pushinteger(L,2);
+ lua_pushinteger(L,b);
+ lua_settable(L,-3);
+
+ return 1;
+}
int popvector3i(lua_State* L,long* a,long* b,long* c){//{v3}
lua_pushinteger(L,1);//{v3},1
@@ -114,3 +127,17 @@ int popvector3d(lua_State* L,double* a,double* b,double* c){
lua_pop(L,1);
return 0;
}
+
+int popvector2i(lua_State* L, long* a, long* b){
+ lua_pushinteger(L,1);
+ lua_gettable(L,-2);
+ *a = lua_tonumber(L,-1);
+ lua_pop(L,1);
+
+ lua_pushinteger(L,2);
+ lua_gettable(L,-2);
+ *b = lua_tonumber(L,-1);
+ lua_pop(L,2);
+
+ return 0;
+}
diff --git a/src/shared/lua_api/common.h b/src/shared/lua_api/common.h
index 81dc3a4..9260706 100644
--- a/src/shared/lua_api/common.h
+++ b/src/shared/lua_api/common.h
@@ -9,5 +9,8 @@ void loadLLibs(lua_State*);
int pushvector3i(lua_State*,long,long,long);
int pushvector3d(lua_State*,double,double,double);
+int pushvector2i(lua_State*,long,long);
+
int popvector3i(lua_State*,long*,long*,long*);
int popvector3d(lua_State*,double*,double*,double*);
+int popvector2i(lua_State*,long*,long*);
diff --git a/src/shared/lua_api/irr/cubenode.cpp b/src/shared/lua_api/irr/cubenode.cpp
new file mode 100644
index 0000000..d7e87bb
--- /dev/null
+++ b/src/shared/lua_api/irr/cubenode.cpp
@@ -0,0 +1,6 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
diff --git a/src/shared/lua_api/irr/cubenode.hpp b/src/shared/lua_api/irr/cubenode.hpp
new file mode 100644
index 0000000..d7e87bb
--- /dev/null
+++ b/src/shared/lua_api/irr/cubenode.hpp
@@ -0,0 +1,6 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
diff --git a/src/shared/lua_api/load_scene.cpp b/src/shared/lua_api/load_scene.cpp
new file mode 100644
index 0000000..633fcb1
--- /dev/null
+++ b/src/shared/lua_api/load_scene.cpp
@@ -0,0 +1,11 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+
+void register_scene(lua_State* L){
+
+}
diff --git a/src/shared/lua_api/load_scene.hpp b/src/shared/lua_api/load_scene.hpp
new file mode 100644
index 0000000..c83a224
--- /dev/null
+++ b/src/shared/lua_api/load_scene.hpp
@@ -0,0 +1,8 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+void register_scene(lua_State* L);
diff --git a/src/shared/lua_api/phys/bphysbox.cpp b/src/shared/lua_api/phys/bphysbox.cpp
index be9db07..3036cf9 100644
--- a/src/shared/lua_api/phys/bphysbox.cpp
+++ b/src/shared/lua_api/phys/bphysbox.cpp
@@ -26,22 +26,15 @@ static LISceneNode* checkismesh(lua_State* L){
return checkismesh(L,1);
}
*/
-
-// phys.newphysbox(vector3 size, vector3 origin, double mass)
-int newbphysbox(lua_State* L){
- printf("Createing bphysbox!\n");
- int nargs = lua_gettop(L);
- if(nargs != 3){
- lua_pushfstring(L,"Expected 3 arguments, got %d",nargs);
- lua_error(L);
- }
+// ud_btRigidBody :: ({v3 size}, {v3 origin}, double mass)
+void makenewbphysbox(lua_State* L){
double px,py,pz; //position
double sx,sy,sz; //size
double mass;
mass = lua_tonumber(L,-1);//{v3_size},{v3_origin},mass
lua_pop(L,1);//{v3_size},{v3_origin}
- printf("Got mass: %d\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);
@@ -73,9 +66,18 @@ int newbphysbox(lua_State* L){
World->addRigidBody(rigidbody);
Objects.push_back(rigidbody);
+ lua_pushlightuserdata(L,rigidbody);//ud_rigidbody
+}
+
+// phys.newphysbox(vector3 size, vector3 origin, double mass)
+int newbphysbox(lua_State* L){
+ printf("Createing bphysbox!\n");
//Create it's lua representation
+ makenewbphysbox(L);//ud_btRigidBody
+ btRigidBody* r = (btRigidBody*)lua_touserdata(L,-1);
+ lua_pop(L,1);
lua_newtable(L);//{}
- lua_pushlightuserdata(L,rigidbody);//{},ud_rigidbody
+ lua_pushlightuserdata(L,r);//ud_btRigidBody
lua_setfield(L,-2,"rigidbody");//{}
//Set it's metatable
@@ -118,6 +120,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");
lua_getfield(L,-1,"rigidbody");//self,ud_rigidbody
btRigidBody* i = (btRigidBody*)lua_touserdata(L,-1);//self,ud_rigidbody
btTransform bt = i->getWorldTransform();
@@ -145,7 +148,8 @@ void bphysbox_register(lua_State* L){//
lua_pop(L,1);//
lua_getglobal(L,"phys");//{}
- lua_pushcfunction(L,newbphysbox);
- lua_setfield(L,-2,"newphysbox");
+ lua_pushcfunction(L,newbphysbox);//{},newbphysbox()
+ lua_setfield(L,-2,"newphysbox");//{}
+ lua_pop(L,1);
}
diff --git a/src/shared/lua_api/phys/bphysbox.hpp b/src/shared/lua_api/phys/bphysbox.hpp
index c031037..96b58a7 100644
--- a/src/shared/lua_api/phys/bphysbox.hpp
+++ b/src/shared/lua_api/phys/bphysbox.hpp
@@ -11,4 +11,4 @@ extern "C" {
#include "../common.h"
void bphysbox_register(lua_State* L);
-int newbphysbox(lua_State* L);
+void makenewbphysbox(lua_State* L);