mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-31 11:41:51 +02:00
Add missing removeComponent for Lua API
This commit is contained in:
@@ -341,6 +341,7 @@ void LuaScriptInterface::initInterfaceAPI()
|
|||||||
{"showWindow", interface_showWindow},
|
{"showWindow", interface_showWindow},
|
||||||
{"closeWindow", interface_closeWindow},
|
{"closeWindow", interface_closeWindow},
|
||||||
{"addComponent", interface_addComponent},
|
{"addComponent", interface_addComponent},
|
||||||
|
{"removeComponent", interface_addComponent},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
luaL_register(l, "interface", interfaceAPIMethods);
|
luaL_register(l, "interface", interfaceAPIMethods);
|
||||||
@@ -381,6 +382,29 @@ int LuaScriptInterface::interface_addComponent(lua_State * l)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::interface_removeComponent(lua_State * l)
|
||||||
|
{
|
||||||
|
void * luaComponent = NULL;
|
||||||
|
ui::Component * component = NULL;
|
||||||
|
if(luaComponent = Luna<LuaButton>::tryGet(l, 1))
|
||||||
|
component = Luna<LuaButton>::get(luaComponent)->GetComponent();
|
||||||
|
else if(luaComponent = Luna<LuaLabel>::tryGet(l, 1))
|
||||||
|
component = Luna<LuaLabel>::get(luaComponent)->GetComponent();
|
||||||
|
else if(luaComponent = Luna<LuaTextbox>::tryGet(l, 1))
|
||||||
|
component = Luna<LuaTextbox>::get(luaComponent)->GetComponent();
|
||||||
|
else if(luaComponent = Luna<LuaCheckbox>::tryGet(l, 1))
|
||||||
|
component = Luna<LuaCheckbox>::get(luaComponent)->GetComponent();
|
||||||
|
else if(luaComponent = Luna<LuaSlider>::tryGet(l, 1))
|
||||||
|
component = Luna<LuaSlider>::get(luaComponent)->GetComponent();
|
||||||
|
else if(luaComponent = Luna<LuaProgressBar>::tryGet(l, 1))
|
||||||
|
component = Luna<LuaProgressBar>::get(luaComponent)->GetComponent();
|
||||||
|
else
|
||||||
|
luaL_typerror(l, 1, "Component");
|
||||||
|
if(luacon_ci->Window && component)
|
||||||
|
luacon_ci->Window->RemoveComponent(component);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int LuaScriptInterface::interface_showWindow(lua_State * l)
|
int LuaScriptInterface::interface_showWindow(lua_State * l)
|
||||||
{
|
{
|
||||||
LuaWindow * window = Luna<LuaWindow>::check(l, 1);
|
LuaWindow * window = Luna<LuaWindow>::check(l, 1);
|
||||||
|
@@ -89,6 +89,7 @@ class LuaScriptInterface: public CommandInterface
|
|||||||
static int interface_showWindow(lua_State * l);
|
static int interface_showWindow(lua_State * l);
|
||||||
static int interface_closeWindow(lua_State * l);
|
static int interface_closeWindow(lua_State * l);
|
||||||
static int interface_addComponent(lua_State * l);
|
static int interface_addComponent(lua_State * l);
|
||||||
|
static int interface_removeComponent(lua_State * l);
|
||||||
|
|
||||||
//VM
|
//VM
|
||||||
void initVirtualMachineAPI();
|
void initVirtualMachineAPI();
|
||||||
|
@@ -25,6 +25,7 @@ Luna<LuaWindow>::RegType LuaWindow::methods[] = {
|
|||||||
method(LuaWindow, position),
|
method(LuaWindow, position),
|
||||||
method(LuaWindow, size),
|
method(LuaWindow, size),
|
||||||
method(LuaWindow, addComponent),
|
method(LuaWindow, addComponent),
|
||||||
|
method(LuaWindow, removeComponent),
|
||||||
method(LuaWindow, onInitialized),
|
method(LuaWindow, onInitialized),
|
||||||
method(LuaWindow, onExit),
|
method(LuaWindow, onExit),
|
||||||
method(LuaWindow, onTick),
|
method(LuaWindow, onTick),
|
||||||
@@ -122,6 +123,29 @@ int LuaWindow::addComponent(lua_State * l)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaWindow::removeComponent(lua_State * l)
|
||||||
|
{
|
||||||
|
void * luaComponent = NULL;
|
||||||
|
ui::Component * component = NULL;
|
||||||
|
if(luaComponent = Luna<LuaButton>::tryGet(l, 1))
|
||||||
|
component = Luna<LuaButton>::get(luaComponent)->GetComponent();
|
||||||
|
else if(luaComponent = Luna<LuaLabel>::tryGet(l, 1))
|
||||||
|
component = Luna<LuaLabel>::get(luaComponent)->GetComponent();
|
||||||
|
else if(luaComponent = Luna<LuaTextbox>::tryGet(l, 1))
|
||||||
|
component = Luna<LuaTextbox>::get(luaComponent)->GetComponent();
|
||||||
|
else if(luaComponent = Luna<LuaCheckbox>::tryGet(l, 1))
|
||||||
|
component = Luna<LuaCheckbox>::get(luaComponent)->GetComponent();
|
||||||
|
else if(luaComponent = Luna<LuaSlider>::tryGet(l, 1))
|
||||||
|
component = Luna<LuaSlider>::get(luaComponent)->GetComponent();
|
||||||
|
else if(luaComponent = Luna<LuaProgressBar>::tryGet(l, 1))
|
||||||
|
component = Luna<LuaProgressBar>::get(luaComponent)->GetComponent();
|
||||||
|
else
|
||||||
|
luaL_typerror(l, 1, "Component");
|
||||||
|
if(component)
|
||||||
|
window->RemoveComponent(component);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int LuaWindow::position(lua_State * l)
|
int LuaWindow::position(lua_State * l)
|
||||||
{
|
{
|
||||||
int args = lua_gettop(l);
|
int args = lua_gettop(l);
|
||||||
|
@@ -37,6 +37,7 @@ class LuaWindow
|
|||||||
int position(lua_State * l);
|
int position(lua_State * l);
|
||||||
int size(lua_State * l);
|
int size(lua_State * l);
|
||||||
int addComponent(lua_State * l);
|
int addComponent(lua_State * l);
|
||||||
|
int removeComponent(lua_State * l);
|
||||||
|
|
||||||
//Set event handlers
|
//Set event handlers
|
||||||
int onInitialized(lua_State * l);
|
int onInitialized(lua_State * l);
|
||||||
|
Reference in New Issue
Block a user