Commit 2fdba300 authored by mercury233's avatar mercury233 Committed by GitHub

update premake5 & basic support for lua5.4 (#417)

parent d644fb5b
......@@ -17,9 +17,9 @@ interpreter::interpreter(duel* pd): coroutines(256) {
lua_state = luaL_newstate();
current_state = lua_state;
pduel = pd;
memcpy(lua_getextraspace(lua_state), &pd, LUA_EXTRASPACE); //set_duel_info
no_action = 0;
call_depth = 0;
set_duel_info(lua_state, pd);
//Initial
luaL_openlibs(lua_state);
lua_pushnil(lua_state);
......@@ -577,12 +577,19 @@ int32 interpreter::call_coroutine(int32 f, uint32 param_count, uint32 * yield_va
}
}
push_param(rthread, true);
lua_State* prev_state = current_state;
current_state = rthread;
#if (LUA_VERSION_NUM >= 504)
int32 nresults;
int32 result = lua_resume(rthread, prev_state, param_count, &nresults);
#else
int32 result = lua_resume(rthread, 0, param_count);
int32 nresults = lua_gettop(rthread);
#endif
if (result == 0) {
coroutines.erase(f);
if(yield_value) {
if(lua_gettop(rthread) == 0)
if(nresults == 0)
*yield_value = 0;
else if(lua_isboolean(rthread, -1))
*yield_value = lua_toboolean(rthread, -1);
......@@ -662,14 +669,8 @@ int32 interpreter::get_function_handle(lua_State* L, int32 index) {
int32 ref = luaL_ref(L, LUA_REGISTRYINDEX);
return ref;
}
void interpreter::set_duel_info(lua_State* L, duel* pduel) {
lua_pushlightuserdata(L, pduel);
luaL_ref(L, LUA_REGISTRYINDEX);
}
duel* interpreter::get_duel_info(lua_State * L) {
luaL_checkstack(L, 1, NULL);
lua_rawgeti(L, LUA_REGISTRYINDEX, 3);
duel* pduel = (duel*)lua_topointer(L, -1);
lua_pop(L, 1);
duel* pduel;
memcpy(&pduel, lua_getextraspace(L), LUA_EXTRASPACE);
return pduel;
}
......@@ -69,7 +69,6 @@ public:
static void effect2value(lua_State* L, effect* peffect);
static void function2value(lua_State* L, int32 pointer);
static int32 get_function_handle(lua_State* L, int32 index);
static void set_duel_info(lua_State* L, duel* pduel);
static duel* get_duel_info(lua_State* L);
template <size_t N, typename... TR>
......
project "ocgcore"
kind "StaticLib"
files { "**.cc", "**.cpp", "**.c", "**.h" }
configuration "windows"
includedirs { "../lua" }
configuration "not vs*"
buildoptions { "-std=c++14" }
configuration "not windows"
includedirs { "/usr/include/lua5.3" }
project "ocgcore"
kind "StaticLib"
files { "*.cpp", "*.h" }
links { "lua" }
if BUILD_LUA then
includedirs { "../lua/src" }
end
filter "not action:vs*"
buildoptions { "-std=c++14" }
filter "system:bsd"
defines { "LUA_USE_POSIX" }
filter "system:macosx"
defines { "LUA_USE_MACOSX" }
filter "system:linux"
defines { "LUA_USE_LINUX" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment