99 lines
2.3 KiB
C++
99 lines
2.3 KiB
C++
#include "dl_lua_register.h"
|
|
|
|
#include "dl_io.h"
|
|
#include "render/dl_graphics.h"
|
|
#include "system/dl_system.h"
|
|
#include "script/dl_lua.h"
|
|
#include "ui/dl_ui_manager.h"
|
|
|
|
#include <LuaBridge/Array.h>
|
|
|
|
namespace dl
|
|
{
|
|
void lua_log(std::string_view str)
|
|
{
|
|
log(str);
|
|
}
|
|
|
|
|
|
void lua_register_base(lua_State* L)
|
|
{
|
|
luabridge::getGlobalNamespace(L).
|
|
addFunction("log", lua_log);
|
|
}
|
|
|
|
void lua_register_system(lua_State* L)
|
|
{
|
|
luabridge::getGlobalNamespace(L)
|
|
.beginClass<ParamWindow>("ParamWindow")
|
|
.addConstructor<void (*)()>() // 忽略这个构造会出错……
|
|
.addProperty("title", &ParamWindow::_strTitle)
|
|
.endClass();
|
|
|
|
luabridge::getGlobalNamespace(L)
|
|
.beginClass<System>("System")
|
|
.addFunction("SetFuncRun", &System::lua_SetFuncUpdate)
|
|
.addFunction("Start", (void(System::*)(const ParamWindow&))&System::Start)
|
|
.endClass();
|
|
|
|
auto result = luabridge::push(L, g_system);
|
|
lua_setglobal(L, "system");
|
|
}
|
|
|
|
void lua_register_gfx(lua_State* L)
|
|
{
|
|
luabridge::getGlobalNamespace(L)
|
|
.beginClass<Graphics>("Graphics")
|
|
.addFunction("Rectangle2D", &Graphics::Rectangle2D)
|
|
.endClass();
|
|
|
|
auto result = luabridge::push(L, g_gfx);
|
|
lua_setglobal(L, "gfx");
|
|
}
|
|
|
|
void lua_register_ui(lua_State* L)
|
|
{
|
|
using namespace UI;
|
|
luabridge::getGlobalNamespace(L)
|
|
.beginClass<Panel>("UIPanel")
|
|
.addFunction("Add", (void(Panel::*)(UI::Text*))&Panel::Add)
|
|
.endClass();
|
|
|
|
luabridge::getGlobalNamespace(L)
|
|
.beginClass<UI::Text>("UIText")
|
|
.addFunction("SetString", &UI::Text::SetString)
|
|
.addFunction("SetLang", &UI::Text::SetLang)
|
|
.endClass();
|
|
|
|
luabridge::getGlobalNamespace(L)
|
|
.beginClass<Manager>("UIManager")
|
|
.addFunction("CreatePanel", (Panel * (Manager::*)()) & Manager::CreatePanel)
|
|
.addFunction("CreateText", &Manager::CreateText)
|
|
.addFunction("CreateTextDefault", &Manager::CreateTextDefault)
|
|
.endClass();
|
|
|
|
auto result = luabridge::push(L, g_ui);
|
|
lua_setglobal(L, "ui");
|
|
}
|
|
|
|
void lua_register_factory(lua_State* L)
|
|
{
|
|
/*luabridge::getGlobalNamespace(L)
|
|
.beginClass<Factory>("Factory")
|
|
.addFunction("CreateText", &Factory::CreateText)
|
|
.endClass();
|
|
|
|
auto result = luabridge::push(L, g_factory);
|
|
lua_setglobal(L, "factory");*/
|
|
}
|
|
|
|
void lua_register_all(lua_State* L)
|
|
{
|
|
lua_register_base(L);
|
|
lua_register_system(L);
|
|
lua_register_gfx(L);
|
|
lua_register_ui(L);
|
|
lua_register_factory(L);
|
|
}
|
|
|
|
} |