diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-31 18:39:11 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-31 18:39:11 (GMT) |
| commit | 493a32a1b28f15cf02bb69c3735b9a411448c523 (patch) | |
| tree | 838b39db197c1f9cab5740703bb03f9b24702c56 /src/cat/LuaScriptInterface.cpp | |
| parent | 322d224fa7a1d5f155c87596bb2f5927989e9933 (diff) | |
| download | powder-493a32a1b28f15cf02bb69c3735b9a411448c523.zip powder-493a32a1b28f15cf02bb69c3735b9a411448c523.tar.gz | |
Some Lua interface API stuff
Diffstat (limited to 'src/cat/LuaScriptInterface.cpp')
| -rw-r--r-- | src/cat/LuaScriptInterface.cpp | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 84b4b9e..fe098a0 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -25,6 +25,10 @@ #include "LuaBit.h" +#include "LuaLuna.h" +#include "LuaWindow.h" +#include "LuaButton.h" + #ifdef WIN #include <direct.h> #else @@ -48,6 +52,7 @@ LuaScriptInterface::LuaScriptInterface(GameModel * m): luaL_openlibs(l); luaopen_bit(l); + initInterfaceAPI(); initRendererAPI(); initElementsAPI(); @@ -251,10 +256,66 @@ tpt.partsdata = nil"); lua_el_mode[i] = 0; } - //Autorun - luacon_eval("dofile(\"autorun.lua\")"); //Autorun lua script } +void LuaScriptInterface::Init() +{ + if(luacon_eval("dofile(\"autorun.lua\")")) + { + luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); + } +} + +void LuaScriptInterface::SetWindow(ui::Window * window) +{ + Window = window; +} + +//// Begin Interface API + +void LuaScriptInterface::initInterfaceAPI() +{ + struct luaL_reg interfaceAPIMethods [] = { + {"showWindow", interface_showWindow}, + {"closeWindow", interface_closeWindow}, + {"addComponent", interface_addComponent}, + {NULL, NULL} + }; + luaL_register(l, "interface", interfaceAPIMethods); + Luna<LuaWindow>::Register(l); + Luna<LuaButton>::Register(l); +} + +int LuaScriptInterface::interface_addComponent(lua_State * l) +{ + void * luaComponent = NULL; + ui::Component * component = NULL; + if(luaComponent = luaL_checkudata(l, 1, "Button")) + component = Luna<LuaButton>::get(luaComponent)->GetComponent(); + else + luaL_typerror(l, 1, "Component"); + if(luacon_ci->Window && component) + luacon_ci->Window->AddComponent(component); + return 0; +} + +int LuaScriptInterface::interface_showWindow(lua_State * l) +{ + LuaWindow * window = Luna<LuaWindow>::check(l, 1); + if(window && ui::Engine::Ref().GetWindow()!=window->GetWindow()) + ui::Engine::Ref().ShowWindow(window->GetWindow()); + return 0; +} + +int LuaScriptInterface::interface_closeWindow(lua_State * l) +{ + LuaWindow * window = Luna<LuaWindow>::check(l, 1); + if(window && ui::Engine::Ref().GetWindow()==window->GetWindow()) + ui::Engine::Ref().CloseWindow(); + return 0; +} + + //// Begin Renderer API void LuaScriptInterface::initRendererAPI() |
