aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/lua_api')
-rw-r--r--src/client/lua_api/gui/iguibutton.cpp10
-rw-r--r--src/client/lua_api/gui/iguifiledialog.cpp16
-rw-r--r--src/client/lua_api/gui/iguiimage.cpp14
-rw-r--r--src/client/lua_api/load_cphys.cpp13
-rw-r--r--src/client/lua_api/load_video.cpp20
-rw-r--r--src/client/lua_api/phys/cbcharactercontroller.cpp2
-rw-r--r--src/client/lua_api/phys/cbphysbox.cpp13
-rw-r--r--src/client/lua_api/phys/cbphysmodel.cpp12
-rw-r--r--src/client/lua_api/phys/cbphysmodel.hpp2
-rw-r--r--src/client/lua_api/scene/igeneric.cpp18
-rw-r--r--src/client/lua_api/scene/ilight.cpp23
-rw-r--r--src/client/lua_api/video/draw.cpp29
-rw-r--r--src/client/lua_api/video/draw.hpp8
-rw-r--r--src/client/lua_api/video/smaterial.cpp14
14 files changed, 166 insertions, 28 deletions
diff --git a/src/client/lua_api/gui/iguibutton.cpp b/src/client/lua_api/gui/iguibutton.cpp
index 42d2846..b8ff517 100644
--- a/src/client/lua_api/gui/iguibutton.cpp
+++ b/src/client/lua_api/gui/iguibutton.cpp
@@ -30,11 +30,11 @@ char lhashkey[20];
/***
Creates a new button.
Buttons may have the following fields set for callbacks:
-`.onClick(self)`
-`.onFocus(self)`
-`.onUnfocus(self)`
-`.onHover(self)`
-`.onLeave(self)`
+ .onClick(self)
+ .onFocus(self)
+ .onUnfocus(self)
+ .onHover(self)
+ .onLeave(self)
@function newbutton()
@tparam rect dimensions The rectangle to place the button at. If the box has a parent,
it is offset from the upper-left of the parent element.
diff --git a/src/client/lua_api/gui/iguifiledialog.cpp b/src/client/lua_api/gui/iguifiledialog.cpp
index 6303230..d717673 100644
--- a/src/client/lua_api/gui/iguifiledialog.cpp
+++ b/src/client/lua_api/gui/iguifiledialog.cpp
@@ -28,7 +28,11 @@ extern IrrlichtDevice* device;
/***
@function newfileopendialog()
-Creates a new dialog to open a file
+Creates a new dialog to open a file.
+The file creation window may have the following fields set for callbacks:
+ .onDirectorySelect(self)
+ .onFileSelect(self)
+ .onCanceled(self)
@tparam ?string title The rectangle to place the button at. If the box has a parent,
it is offset from the upper-left of the parent element.
@tparam ?string path The path to open the file dialog to
@@ -66,10 +70,10 @@ static int newfileopendialog(lua_State* L){
mbstowcs(title,titlec,titlecslen);
title[titlecslen] = L'\0';
}
-
+ //printf("Got all arguments\n");
IGUIEnvironment *env = device->getGUIEnvironment();
IGUIFileOpenDialog *but = env->addFileOpenDialog(title,modal,parent,-1,false,path);
-
+ //printf("Created file open dialog\n");
//printf("Added file open dialog\n");
lua_newtable(L);//{}
lua_pushlightuserdata(L,but);//{},ud_iguibutton
@@ -78,13 +82,13 @@ static int newfileopendialog(lua_State* L){
lua_setmetatable(L,-2);//{guielement}
//printf("Created lua representation\n");
- setelementcallback(L,EGET_DIRECTORY_SELECTED,"onDirectory");//
- setelementcallback(L,EGET_FILE_SELECTED,"onFileSelected");
+ setelementcallback(L,EGET_DIRECTORY_SELECTED,"onDirectorySelect");//
+ setelementcallback(L,EGET_FILE_SELECTED,"onFileSelect");
setelementcallback(L,EGET_FILE_CHOOSE_DIALOG_CANCELLED,"onCanceled");
//printf("Finished registering callback\n");
free(title);
- free(path);
+ //printf("Freed everything\n");
return 1;
}
diff --git a/src/client/lua_api/gui/iguiimage.cpp b/src/client/lua_api/gui/iguiimage.cpp
index 1d0f4dc..267cbd2 100644
--- a/src/client/lua_api/gui/iguiimage.cpp
+++ b/src/client/lua_api/gui/iguiimage.cpp
@@ -21,6 +21,7 @@ extern "C" {
@module gui
*/
using namespace irr;
+using namespace video;
using namespace gui;
extern IrrlichtDevice* device;
@@ -80,8 +81,21 @@ int setcolor(lua_State* L){
return 0;
}
+//setimage(self,itexture)
+int setimage(lua_State *L){
+ lua_getfield(L,-1,"texture");//{iguiimg},{itex}
+ ITexture* img = (ITexture*)lua_touserdata(L,-1);//{iguiimg},{itex},ud_itexture
+ lua_pop(L,2);//{iguiimg}
+ lua_getfield(L,-1,"guielement");//{iguiimg},ud_guiimg
+ IGUIImage *gimg = (IGUIImage*)lua_touserdata(L,-1);//{iguiimg},ud_guiimg
+ lua_pop(L,2);//
+ gimg->setImage(img);
+ return 0;
+}
+
static const luaL_reg iguiimage_m[] = {
{"setcolor", setcolor},
+ {"setimage", setimage},
{0, 0},
};
diff --git a/src/client/lua_api/load_cphys.cpp b/src/client/lua_api/load_cphys.cpp
index 92eaff0..2e2d18a 100644
--- a/src/client/lua_api/load_cphys.cpp
+++ b/src/client/lua_api/load_cphys.cpp
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <vector>
#include <map>
+#include <assert.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -31,8 +32,8 @@ extern btBroadphaseInterface *BroadPhase;
int raytest(lua_State *L){
double fx,fy,fz;
double tx,ty,tz;
- popvector3d(L, &fx, &fy, &fz);
popvector3d(L, &tx, &ty, &tz);
+ popvector3d(L, &fx, &fy, &fz);
btVector3 from(fx, fy, fz);
btVector3 to(tx, ty, tz);
@@ -44,15 +45,23 @@ int raytest(lua_State *L){
}
void load_cphysfuncs(lua_State* L){
-
+ assert(lua_gettop(L) == 0);
+ printf("Registering cphysbox\n");
//phys things
+ assert(lua_gettop(L) == 0);
cbphysbox_register(L);
+ assert(lua_gettop(L) == 0);
cbcharactercontroller_register(L);
+ assert(lua_gettop(L) == 0);
cbphysmodel_register(L);
+ assert(lua_gettop(L) == 0);
bghostobject_register(L);
+ assert(lua_gettop(L) == 0);
+ assert(lua_gettop(L) == 0);
lua_getglobal(L,"phys");//{}
lua_pushcfunction(L,raytest);//{},raytest()
lua_setfield(L,-2,"raytest");//{}
lua_pop(L,1);
+ assert(lua_gettop(L) == 0);
}
diff --git a/src/client/lua_api/load_video.cpp b/src/client/lua_api/load_video.cpp
index f309180..b3487ca 100644
--- a/src/client/lua_api/load_video.cpp
+++ b/src/client/lua_api/load_video.cpp
@@ -8,6 +8,7 @@ extern "C" {
#include "video/smaterial.hpp"
#include "video/itexture.hpp"
#include "video/iimage.hpp"
+#include "video/draw.hpp"
#include <shared/lua_api/common.hpp>
@@ -79,6 +80,20 @@ int draw2dline(lua_State* L){
return 0;
}
+//{sx,sy,sz},{ex,ey,ez},{color}
+int draw3dline(lua_State* L){
+ double sx,sy,sz;
+ double ex,ey,ez;
+ long r,g,b,a;
+ popvector4i(L,&r,&g,&b,&a);
+ popvector3d(L,&ex,&ey,&ez);
+ popvector3d(L,&sx,&sy,&sz);
+
+ driver->draw3DLine(vector3df(sx,sy,sz),vector3df(ex,ey,ez),SColor(a,r,g,b));
+
+ return 0;
+}
+
void load_videofuncs(lua_State* L){
//printf("Loading video libraries...\n");
lua_newtable(L);//{}
@@ -88,11 +103,14 @@ void load_videofuncs(lua_State* L){
lua_pushcfunction(L,draw2dimage);//{},draw2dimage()
lua_setfield(L,-2,"drawtexture");//{}
lua_pushcfunction(L,draw2dline);//{},draw2dline()
- lua_setfield(L,-2,"drawline");//{}
+ lua_setfield(L,-2,"draw2dline");//{}
+ lua_pushcfunction(L,draw3dline);
+ lua_setfield(L,-2,"draw3dline");
lua_pop(L,1);//
smaterial_register(L);
itexture_register(L);
iimage_register(L);
+ draw_register(L);
}
diff --git a/src/client/lua_api/phys/cbcharactercontroller.cpp b/src/client/lua_api/phys/cbcharactercontroller.cpp
index 6a6da96..16ad1ad 100644
--- a/src/client/lua_api/phys/cbcharactercontroller.cpp
+++ b/src/client/lua_api/phys/cbcharactercontroller.cpp
@@ -115,6 +115,4 @@ void cbcharactercontroller_register(lua_State* L){
//printf("When registering physbox, new() is %p\n",newcbphysbox);
//printf("setpos is %p\n",cbphyssetpos);
- lua_pop(L,1);
-
}
diff --git a/src/client/lua_api/phys/cbphysbox.cpp b/src/client/lua_api/phys/cbphysbox.cpp
index 3c0f97d..e675a04 100644
--- a/src/client/lua_api/phys/cbphysbox.cpp
+++ b/src/client/lua_api/phys/cbphysbox.cpp
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <list>
+#include <assert.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -163,12 +164,15 @@ static const luaL_reg cbphysbox_m[] = {
};
void cbphysbox_register(lua_State* L){
+ assert(lua_gettop(L) == 0);
bphysbox_register(L);//
+ assert(lua_gettop(L) == 0);
lua_getglobal(L,"phys");//{}
lua_pushcfunction(L,newcbphysbox);//{},newcbphysbox()
- lua_setfield(L,-2,"newcphysbox");//{}
+ lua_setfield(L,-2,"newphysbox");//{phys}
lua_pop(L,1);//
+ assert(lua_gettop(L) == 0);
luaL_getmetatable(L,"phys.physbox");//phys.physbox
lua_newtable(L);//phys.physbox,{}
@@ -176,15 +180,14 @@ void cbphysbox_register(lua_State* L){
luaL_register(L,NULL,brigidbody_m);
luaL_register(L,NULL,igeneric_m);
luaL_register(L,NULL,cbphysbox_m);//phys.physbox,{}
- lua_pushstring(L,"rigidbody");
- lua_setfield(L,-2,"type");
+ lua_pushstring(L,"rigidbody");//phys.physbox,{},"rigidbody"
+ lua_setfield(L,-2,"type");//phys.physbox,{}
lua_setfield(L,-2,"__index");//phys.physbox
lua_pop(L,1);
-
//printf("When registering physbox, new() is %p\n",newcbphysbox);
//printf("setpos is %p\n",cbphyssetpos);
- lua_pop(L,1);
+ assert(lua_gettop(L) == 0);
}
diff --git a/src/client/lua_api/phys/cbphysmodel.cpp b/src/client/lua_api/phys/cbphysmodel.cpp
index ac27288..ae2559e 100644
--- a/src/client/lua_api/phys/cbphysmodel.cpp
+++ b/src/client/lua_api/phys/cbphysmodel.cpp
@@ -6,6 +6,7 @@
#include <map>
#include <functional>
#include <list>
+#include <assert.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -260,9 +261,12 @@ static const luaL_reg bphysmodel_m[] = {
{0, 0},
};
-int cbphysmodel_register(lua_State* L){
+void cbphysmodel_register(lua_State* L){
+ assert(lua_gettop(L) == 0);
bphysmodel_register(L);
+ assert(lua_gettop(L) == 0);
+ assert(lua_gettop(L) == 0);
luaL_getmetatable(L,"phys.physmodel");//{physmodel_m}
lua_getfield(L,-1,"__index");//{physmodel_m},{}
luaL_register(L,NULL,igeneric_m); //Inherit all the things to do with scene nodes
@@ -270,9 +274,11 @@ int cbphysmodel_register(lua_State* L){
luaL_register(L,NULL,brigidbody_m);//Add rigidbody things
luaL_register(L,NULL,bphysmodel_m);//anything specific?
lua_pop(L,2);
+ assert(lua_gettop(L) == 0);
+ assert(lua_gettop(L) == 0);
lua_getglobal(L,"phys");
luaL_register(L,NULL,bphysmodel_f);
-
- return 1;
+ lua_pop(L,1);
+ assert(lua_gettop(L) == 0);
}
diff --git a/src/client/lua_api/phys/cbphysmodel.hpp b/src/client/lua_api/phys/cbphysmodel.hpp
index 5ea42a8..d8495d2 100644
--- a/src/client/lua_api/phys/cbphysmodel.hpp
+++ b/src/client/lua_api/phys/cbphysmodel.hpp
@@ -8,5 +8,5 @@ extern "C" {
}
#include <irrlicht.h>
-int cbphysmodel_register(lua_State* L);
+void cbphysmodel_register(lua_State* L);
#endif
diff --git a/src/client/lua_api/scene/igeneric.cpp b/src/client/lua_api/scene/igeneric.cpp
index 63bf4bc..dcac022 100644
--- a/src/client/lua_api/scene/igeneric.cpp
+++ b/src/client/lua_api/scene/igeneric.cpp
@@ -161,6 +161,23 @@ int iscenesetscale(lua_State *L){
}
/***
+Sets the visibility of this scene element
+@function iscenenode:setvisible(bool)
+@tparam boolean visible Sets the visibility for this element
+*/
+//setvisible(true|false)
+int iscenesetvisible(lua_State *L){
+ int visible = lua_toboolean(L,-1);
+ lua_pop(L,1);
+ lua_getfield(L, -1, "node");
+ ISceneNode *i = (ISceneNode*)lua_touserdata(L,-1);//{node=ud_ISceneNode}, ud_ISceneNode
+ lua_pop(L,2);
+
+ i->setVisible(visible == 1);
+ return 0;
+}
+
+/***
Get the scale of this scene element.
@function iscenenode:getscale()
@treturn vector3d The scale scale of this element.
@@ -208,5 +225,6 @@ extern const luaL_reg igeneric_m[] = {
{"setscale", iscenesetscale},
{"getscale", iscenegetscale},
{"remove", isceneremove},
+ {"setvisible", iscenesetvisible},
{0, 0},
};
diff --git a/src/client/lua_api/scene/ilight.cpp b/src/client/lua_api/scene/ilight.cpp
index 972de83..1e292ee 100644
--- a/src/client/lua_api/scene/ilight.cpp
+++ b/src/client/lua_api/scene/ilight.cpp
@@ -17,6 +17,7 @@ extern "C" {
#include <shared/lua_api/common.hpp>
using namespace irr;
+using namespace video;
using namespace scene;
using namespace core;
@@ -27,9 +28,9 @@ static int newiscenelight(lua_State* L){
printf("Createing light!\n");
double x,y,z;
popvector3d(L,&x,&y,&z);//radius
- double radius = lua_tonumber(L,-1);
+ double radius = lua_tonumber(L,-1);
lua_pop(L,1);//
-
+
//Create the mesh
ISceneManager* smgr = device->getSceneManager();
ILightSceneNode* light = smgr->addLightSceneNode(0,vector3df(x,y,z),video::SColor(1.0f,1.0f,1.0f,1.0f),(f32)radius,(s32)-1);
@@ -45,11 +46,23 @@ static int newiscenelight(lua_State* L){
return 1;
- }
+}
+
+//settype(self,const)
+int settype(lua_State *L){
+ video::E_LIGHT_TYPE type = (video::E_LIGHT_TYPE)lua_tonumber(L,-1);//self,type
+ lua_pop(L,1);//self
+ lua_getfield(L,-1,"node");//self,ud_ILightSceneNode
+ ILightSceneNode *light = (ILightSceneNode*)lua_touserdata(L,-1);
+ lua_pop(L,2);//
+ light->setLightType(type);
+ return 0;
+}
static const luaL_reg ilight_m[] = {
{"getpos", iscenegetpos},
{"setpos", iscenesetpos},
+ {"settype", settype},
{0, 0},
};
@@ -59,6 +72,10 @@ void ilight_register(lua_State* L){
lua_pushcfunction(L,newiscenelight);//{scene},newiscenelight()
lua_setfield(L,-2,"newlight");//{scene}
+ set_const(L,ELT_POINT);
+ set_const(L,ELT_SPOT);
+ set_const(L,ELT_DIRECTIONAL);
+
lua_pop(L,1);//
luaL_newmetatable(L,"scene.ilight");//scene.ilight
diff --git a/src/client/lua_api/video/draw.cpp b/src/client/lua_api/video/draw.cpp
new file mode 100644
index 0000000..1f38f34
--- /dev/null
+++ b/src/client/lua_api/video/draw.cpp
@@ -0,0 +1,29 @@
+
+#include <irrlicht.h>
+#include <shared/lua_api/common.hpp>
+#include "draw.hpp"
+
+using namespace irr;
+using namespace video;
+using namespace core;
+
+extern IrrlichtDevice* device;
+extern IVideoDriver* driver;
+//drawline2d {startx,starty},{endx,endy},{r,g,b,a}
+int drawline2d(lua_State *L){
+ long r,g,b,a;
+ popvector4i(L, &r, &g, &b, &a);
+ long endx, endy;
+ popvector2i(L, &endx, &endy);
+ long startx, starty;
+ popvector2i(L, &startx, &starty);
+ driver->draw2DLine(position2d<s32>(startx, starty), position2d<s32>(endx,endy), SColor(r,g,b,a));
+ return 0;
+}
+
+void draw_register(lua_State *L){
+ lua_getglobal(L,"video");//{video}
+ lua_pushcfunction(L,drawline2d);//{video},drawline2d()
+ lua_setfield(L,-2,"drawline2d");//{video}
+ lua_pop(L,1);//
+}
diff --git a/src/client/lua_api/video/draw.hpp b/src/client/lua_api/video/draw.hpp
new file mode 100644
index 0000000..eb5a9a7
--- /dev/null
+++ b/src/client/lua_api/video/draw.hpp
@@ -0,0 +1,8 @@
+
+extern "C" {
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+void draw_register(lua_State* L);
diff --git a/src/client/lua_api/video/smaterial.cpp b/src/client/lua_api/video/smaterial.cpp
index 2ef7053..510748c 100644
--- a/src/client/lua_api/video/smaterial.cpp
+++ b/src/client/lua_api/video/smaterial.cpp
@@ -38,8 +38,22 @@ int setTexture(lua_State* L){
return 0;
}
+//{Material},flag,state
+int setFlag(lua_State* L){
+ int b = lua_toboolean(L,-1);//{material},flag,state
+ lua_pop(L,1);//{material},flag
+ int flag = lua_tonumber(L,-1);//{material},flag
+ lua_pop(L,1);//{material}
+ lua_getfield(L,-1,"smaterial");//{material},ud_material
+ SMaterial* mat = (SMaterial*)lua_touserdata(L,-1);
+ lua_pop(L,2);
+ mat->setFlag((E_MATERIAL_FLAG)flag,b == 1 ? true : false);
+ return 0;
+}
+
static const luaL_reg smaterial_m[] = {
{"setTexture", setTexture},
+ {"setFlag", setFlag},
{0,0},
};