#include "LuaPlugin.h" #include "LuaDocumentElementInstancer.h" #include "LuaEventListenerInstancer.h" #include "RmlUi.h" #include #include #include #include #include #include // the types I made #include "Colourb.h" #include "Colourf.h" #include "Context.h" #include "ContextDocumentsProxy.h" #include "Document.h" #include "Element.h" #include "ElementAttributesProxy.h" #include "ElementChildNodesProxy.h" #include "ElementInstancer.h" #include "ElementStyleProxy.h" #include "ElementText.h" #include "Event.h" #include "EventParametersProxy.h" #include "GlobalLuaFunctions.h" #include "Log.h" #include "RmlUiContextsProxy.h" #include "Vector2f.h" #include "Vector2i.h" // Control types #include "Elements/ElementForm.h" #include "Elements/ElementFormControl.h" #include "Elements/ElementFormControlInput.h" #include "Elements/ElementFormControlSelect.h" #include "Elements/ElementFormControlTextArea.h" #include "Elements/ElementTabSet.h" #include "Elements/SelectOptionsProxy.h" namespace Rml { namespace Lua { static lua_State* g_L = nullptr; /** This will populate the global Lua table with all of the Lua core types by calling LuaType::Register @remark This is called automatically by LuaPlugin::OnInitialise(). */ static void RegisterTypes(); LuaPlugin::LuaPlugin(lua_State* lua_state) { RMLUI_ASSERT(g_L == nullptr); g_L = lua_state; } int LuaPlugin::GetEventClasses() { return EVT_BASIC; } void LuaPlugin::OnInitialise() { if (g_L == nullptr) { Log::Message(Log::LT_INFO, "Loading Lua plugin using a new Lua state."); g_L = luaL_newstate(); luaL_openlibs(g_L); owns_lua_state = true; } else { Log::Message(Log::LT_INFO, "Loading Lua plugin using the provided Lua state."); owns_lua_state = false; } RegisterTypes(); lua_document_element_instancer = new LuaDocumentElementInstancer(); lua_event_listener_instancer = new LuaEventListenerInstancer(); Factory::RegisterElementInstancer("body", lua_document_element_instancer); Factory::RegisterEventListenerInstancer(lua_event_listener_instancer); } void LuaPlugin::OnShutdown() { delete lua_document_element_instancer; delete lua_event_listener_instancer; lua_document_element_instancer = nullptr; lua_event_listener_instancer = nullptr; if (owns_lua_state) lua_close(g_L); g_L = nullptr; delete this; } static void RegisterTypes() { RMLUI_ASSERT(g_L); lua_State* L = g_L; LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); // things that inherit from Element LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); // Proxy tables LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); OverrideLuaGlobalFunctions(L); // push the global variable "rmlui" to use the "RmlUi" methods LuaRmlUiPushrmluiGlobal(L); // Control types LuaType::Register(L); LuaType::Register(L); // Inherits from ElementFormControl LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); LuaType::Register(L); // proxy tables LuaType::Register(L); } lua_State* LuaPlugin::GetLuaState() { return g_L; } } // namespace Lua } // namespace Rml