aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/scene/icube.cpp
blob: d18db2a21bb1ae37aac97a20f97b649e1ca6fa18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
extern "C" {
  #include <lua.h>
  #include <lauxlib.h>
  #include <lualib.h>
}
#include <irrlicht.h>

extern IrrlichtDevice* device;

using namespace irr;

// {} :: scene.newcube(num_size, {v3 pos})
int newiscenecube(lua_StatE* L){//num_size, {v3 pos}
	double x,y,z;
	popvector3d(L,&x, &y, &z);//num_size
	double size = lua_tonumber(L,-1);//num_size
	lua_pop(L,1);//
	IMeshSceneNode* n = device->getSceneManager()->addCubeSceneNode(size,0,-1,core::vector3df(x,y,z));

	lua_newtable(L);//{}
	lua_pushlightuserdata(L,n);//{},ud_node
	lua_setfield(L,-2,"node");//{}

	luaL_getmetatable(L,"scene.inode");//{},sene.inode
	lua_setmetatable(L,-2);

	return 1;
}

static const luaL_reg iscenenode_m[] = {
	{"getpos",        iscenegetpos},
	{"setpos",        iscenesetpos},
//	{"remove",        removeiguielement},
	{0, 0},
};

void icube_register(lua_State* L){

	luaL_newmetatable(L, "scene.icamera");//scene.icamera
	lua_newtable(L);//scene.icamera, {}
	luaL_register(L,NULL,icamera_m);//scene.icamera, {}
	lua_setfield(L,-2,"__index");//scene.icamera
	lua_pop(L,1);//

	luaL_newmetatable(L, "scene.imayacamera");//scene.imayacamera
	lua_newtable(L);//scene.imayascamera,{}
	luaL_register(L,NULL,imayacamera_m);//scene.imayascamera,{}
	lua_setfield(L,-2,"__index");//scene.imayascamera
	lua_pop(L,1);//

	luaL_newmetatable(L,"scene.ifpscamera");//scene.ifpscamera
	lua_newtable(L);//scene.ifpscamera, {}
	luaL_register(L,NULL,ifpscamera_m);//scene.ifpscamera,{}
	luaL_register(L,NULL,icamera_m);//scene.ifpscamera,{}
	lua_setfield(L,-2,"__index");//scene.ifpscamera
	lua_pop(L,1);//

	lua_getglobal(L,"scene");//{}
	lua_pushcfunction(L,newiscenecamera);//{},newiscenecamera()
	lua_setfield(L,-2,"newcamera");//{}
	lua_pushcfunction(L,newiscenefpscamera);//{},newiscenefpscamera()
	lua_setfield(L,-2,"newfpscamera");//{}
	lua_pushcfunction(L,newiscenemayacamera);//{},newiscenemayacamera()
	lua_setfield(L,-2,"newmayacamera");//{}
	printf("\"scene\" was set!\n");	
	//lua_pop(L,1);
}