Skip to content

Commit

Permalink
start LuaManager
Browse files Browse the repository at this point in the history
for now it runs a simple test script on init()
  • Loading branch information
CPunch committed Dec 13, 2023
1 parent 27ccda5 commit 95f2920
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/lua/Manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "lua/Manager.hpp"

#include <iostream>

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);
}
}
}
7 changes: 7 additions & 0 deletions src/lua/Manager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "lua/Thread.hpp"

namespace LuaManager {
void init();
}
14 changes: 14 additions & 0 deletions src/lua/Thread.hpp
Original file line number Diff line number Diff line change
@@ -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) {}
};
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "Eggs.hpp"
#include "Rand.hpp"

#include "lua/Manager.hpp"

#include "settings.hpp"
#include "sandbox/Sandbox.hpp"

Expand Down Expand Up @@ -138,6 +140,7 @@ int main() {
Trading::init();

Database::open();
LuaManager::init();

switch (settings::EVENTMODE) {
case 0: break; // no event
Expand Down

0 comments on commit 95f2920

Please sign in to comment.