From b8b93e0bed93a80a9b4b07cb30ff9af3f0c8e839 Mon Sep 17 00:00:00 2001 From: emb <> Date: Fri, 30 Oct 2015 22:44:56 -0500 Subject: [PATCH] Starting lua branch --- RetroFE/Source/Lua.cpp | 35 +++++++++++++++++++++++++++++++++++ RetroFE/Source/Lua.h | 19 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 RetroFE/Source/Lua.cpp create mode 100644 RetroFE/Source/Lua.h diff --git a/RetroFE/Source/Lua.cpp b/RetroFE/Source/Lua.cpp new file mode 100644 index 0000000..555708d --- /dev/null +++ b/RetroFE/Source/Lua.cpp @@ -0,0 +1,35 @@ +#include "Lua.h" +#include + +Lua::Lua() + : state(NULL) +{ +} + +void Lua::initialize() +{ + /* initialize Lua */ + state = luaL_newstate(); + + /* load Lua base libraries */ + luaL_openlibs(state); + + lua_getglobal( state, "package" ); + lua_getfield( state, -1, "path" ); // get field "path" from table at top of stack (-1) + std::string cur_path = lua_tostring( state, -1 ); // grab path string from top of stack + cur_path.append( ";" ); // do your path magic here + cur_path.append( "../assets/?.lua;" ); + lua_pop( state, 1 ); // get rid of the string on the stack we just pushed on line 5 + lua_pushstring( state, cur_path.c_str() ); // push the new one + lua_setfield( state, -2, "path" ); // set the field "path" in table at -2 with value at top of stack + lua_pop( state, 1 ); // get rid of package table from top of stack +} + +void Lua::deInitialize() +{ + if(state) + { + lua_close(state); + state = NULL; + } +} diff --git a/RetroFE/Source/Lua.h b/RetroFE/Source/Lua.h new file mode 100644 index 0000000..9ef5c51 --- /dev/null +++ b/RetroFE/Source/Lua.h @@ -0,0 +1,19 @@ +#pragma once + +#include +extern "C" { + #include "lua.h" + #include "lualib.h" + #include "lauxlib.h" +} + + +class Lua +{ +public: + Lua(); + void initialize(); + void deInitialize(); + lua_State* state; + +};