From 95f2920f5c696237729f826ebc7b0493b75f9136 Mon Sep 17 00:00:00 2001 From: CPunch Date: Wed, 13 Dec 2023 16:42:40 -0600 Subject: [PATCH] start LuaManager for now it runs a simple test script on init() --- src/lua/Manager.cpp | 15 +++++++++++++++ src/lua/Manager.hpp | 7 +++++++ src/lua/Thread.hpp | 14 ++++++++++++++ src/main.cpp | 3 +++ 4 files changed, 39 insertions(+) create mode 100644 src/lua/Manager.cpp create mode 100644 src/lua/Manager.hpp create mode 100644 src/lua/Thread.hpp diff --git a/src/lua/Manager.cpp b/src/lua/Manager.cpp new file mode 100644 index 0000000..af89e6d --- /dev/null +++ b/src/lua/Manager.cpp @@ -0,0 +1,15 @@ +#include "lua/Manager.hpp" + +#include + +namespace LuaManager { + void init() { + lua_State *L = luaL_newstate(); + luaL_openlibs(L); + + if (luaL_dostring(L, "print(\"Hello from Lua!\")")) { + std::cout << "Lua error: " << lua_tostring(L, -1) << std::endl; + lua_pop(L, 1); + } + } +} \ No newline at end of file diff --git a/src/lua/Manager.hpp b/src/lua/Manager.hpp new file mode 100644 index 0000000..7608505 --- /dev/null +++ b/src/lua/Manager.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "lua/Thread.hpp" + +namespace LuaManager { + void init(); +} \ No newline at end of file diff --git a/src/lua/Thread.hpp b/src/lua/Thread.hpp new file mode 100644 index 0000000..c115939 --- /dev/null +++ b/src/lua/Thread.hpp @@ -0,0 +1,14 @@ +#pragma once + +extern "C" { +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" +} + +struct LuaThread { + lua_State *L; + int ref; + + LuaThread(lua_State *L, int ref) : L(L), ref(ref) {} +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 288e537..0b183cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,6 +24,8 @@ #include "Eggs.hpp" #include "Rand.hpp" +#include "lua/Manager.hpp" + #include "settings.hpp" #include "sandbox/Sandbox.hpp" @@ -138,6 +140,7 @@ int main() { Trading::init(); Database::open(); + LuaManager::init(); switch (settings::EVENTMODE) { case 0: break; // no event