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
|
/*This file defines some things that all igui stuff can do*/
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
#include <irrlicht.h>
#include "../guiparts.hpp"
#include "iguielement.hpp"
#include <shared/lua_api/common.hpp>
using namespace irr;
using namespace gui;
using namespace core;
extern IrrlichtDevice* device;
//new({startx,starty},{endx,endy},"checkbox_name"[,ud_parent])
int newiguicheckbox(lua_State* L){
IGUIElement* par = 0;
if(lua_gettop(L) > 3){
par = (IGUIElement*)lua_touserdata(L,-1);//{startx,starty},{endx,endy},"checkbox_name",ud_parent
printf("Checkbox's parent was %p\n",par);
lua_pop(L,1);//{startx,starty},{endx,endy},"checkbox_name"
}
const char* text = lua_tostring(L,-1);
//int tlen = strlen(text);
lua_pop(L,1);//{startx,starty},{endx,endy}
long startx,starty,endx,endy;
popvector2i(L,&endx,&endy);//{startx,starty}
popvector2i(L,&startx, &starty);//
irr::gui::IGUICheckBox* cb = device->getGUIEnvironment()->addCheckBox(false,core::rect<int>(startx,starty,endx,endy),par,-1,stringw(text).c_str());
lua_pushlightuserdata(L,cb);//*checkbox
luaL_getmetatable(L,"gui.checkbox");//*checkbox,m{gui.checkbox}
lua_setmetatable(L,-2);//*checkbox
return 1;
}
static const luaL_reg iguicheckbox_m[] = {
{"move", moveiguielement},
{"setText", setiguitext},
//{"remove", guisethandeler},
{0,0},
};
int iguicheckbox_register(lua_State* L){//
luaL_newmetatable(L,"gui.checkbox");//m{gui.checkbox}
luaL_register(L,NULL,iguicheckbox_m);
lua_pop(L,1);//
lua_getglobal(L,"gui");//{gui}
lua_pushstring(L,"newcheckbox");//{gui},new(),"newcheckbox"
lua_pushcfunction(L,newiguicheckbox);//{gui},new()
lua_settable(L,-3);//{gui}
lua_pop(L,1);
return 0;
}
|