Commit 94c6544e authored by fallenstardust's avatar fallenstardust

sync ocgcore

parent f4a2b27a
...@@ -17,9 +17,9 @@ interpreter::interpreter(duel* pd): coroutines(256) { ...@@ -17,9 +17,9 @@ interpreter::interpreter(duel* pd): coroutines(256) {
lua_state = luaL_newstate(); lua_state = luaL_newstate();
current_state = lua_state; current_state = lua_state;
pduel = pd; pduel = pd;
memcpy(lua_getextraspace(lua_state), &pd, LUA_EXTRASPACE); //set_duel_info
no_action = 0; no_action = 0;
call_depth = 0; call_depth = 0;
set_duel_info(lua_state, pd);
//Initial //Initial
luaL_openlibs(lua_state); luaL_openlibs(lua_state);
lua_pushnil(lua_state); lua_pushnil(lua_state);
...@@ -577,12 +577,25 @@ int32 interpreter::call_coroutine(int32 f, uint32 param_count, uint32 * yield_va ...@@ -577,12 +577,25 @@ int32 interpreter::call_coroutine(int32 f, uint32 param_count, uint32 * yield_va
} }
} }
push_param(rthread, true); push_param(rthread, true);
lua_State* prev_state = current_state;
current_state = rthread; 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 result = lua_resume(rthread, 0, param_count);
int32 nresults = lua_gettop(rthread);
#endif
if (result == 0) { if (result == 0) {
coroutines.erase(f); coroutines.erase(f);
if(yield_value) if(yield_value) {
*yield_value = lua_isboolean(rthread, -1) ? lua_toboolean(rthread, -1) : (uint32)lua_tointeger(rthread, -1); if(nresults == 0)
*yield_value = 0;
else if(lua_isboolean(rthread, -1))
*yield_value = lua_toboolean(rthread, -1);
else
*yield_value = (uint32)lua_tointeger(rthread, -1);
}
current_state = lua_state; current_state = lua_state;
call_depth--; call_depth--;
if(call_depth == 0) { if(call_depth == 0) {
...@@ -656,14 +669,8 @@ int32 interpreter::get_function_handle(lua_State* L, int32 index) { ...@@ -656,14 +669,8 @@ int32 interpreter::get_function_handle(lua_State* L, int32 index) {
int32 ref = luaL_ref(L, LUA_REGISTRYINDEX); int32 ref = luaL_ref(L, LUA_REGISTRYINDEX);
return ref; 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) { duel* interpreter::get_duel_info(lua_State * L) {
luaL_checkstack(L, 1, NULL); duel* pduel;
lua_rawgeti(L, LUA_REGISTRYINDEX, 3); memcpy(&pduel, lua_getextraspace(L), LUA_EXTRASPACE);
duel* pduel = (duel*)lua_topointer(L, -1);
lua_pop(L, 1);
return pduel; return pduel;
} }
...@@ -67,7 +67,6 @@ public: ...@@ -67,7 +67,6 @@ public:
static void effect2value(lua_State* L, effect* peffect); static void effect2value(lua_State* L, effect* peffect);
static void function2value(lua_State* L, int32 pointer); static void function2value(lua_State* L, int32 pointer);
static int32 get_function_handle(lua_State* L, int32 index); 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); static duel* get_duel_info(lua_State* L);
template <size_t N, typename... TR> template <size_t N, typename... TR>
......
...@@ -1170,13 +1170,13 @@ int32 scriptlib::duel_is_environment(lua_State *L) { ...@@ -1170,13 +1170,13 @@ int32 scriptlib::duel_is_environment(lua_State *L) {
int32 ret = 0, fc = 0; int32 ret = 0, fc = 0;
if(loc & (LOCATION_FZONE + LOCATION_SZONE)) { if(loc & (LOCATION_FZONE + LOCATION_SZONE)) {
card* pcard = pduel->game_field->player[0].list_szone[5]; card* pcard = pduel->game_field->player[0].list_szone[5];
if(pcard && pcard->is_position(POS_FACEUP) && pcard->get_status(STATUS_EFFECT_ENABLED)) { if(pcard && pcard->is_position(POS_FACEUP)) {
fc = 1; fc = 1;
if(code == pcard->get_code() && (playerid == 0 || playerid == PLAYER_ALL)) if(code == pcard->get_code() && (playerid == 0 || playerid == PLAYER_ALL))
ret = 1; ret = 1;
} }
pcard = pduel->game_field->player[1].list_szone[5]; pcard = pduel->game_field->player[1].list_szone[5];
if(pcard && pcard->is_position(POS_FACEUP) && pcard->get_status(STATUS_EFFECT_ENABLED)) { if(pcard && pcard->is_position(POS_FACEUP)) {
fc = 1; fc = 1;
if(code == pcard->get_code() && (playerid == 1 || playerid == PLAYER_ALL)) if(code == pcard->get_code() && (playerid == 1 || playerid == PLAYER_ALL))
ret = 1; ret = 1;
...@@ -1185,13 +1185,13 @@ int32 scriptlib::duel_is_environment(lua_State *L) { ...@@ -1185,13 +1185,13 @@ int32 scriptlib::duel_is_environment(lua_State *L) {
if(!ret && (loc & LOCATION_SZONE)) { if(!ret && (loc & LOCATION_SZONE)) {
if(playerid == 0 || playerid == PLAYER_ALL) { if(playerid == 0 || playerid == PLAYER_ALL) {
for(auto& pcard : pduel->game_field->player[0].list_szone) { for(auto& pcard : pduel->game_field->player[0].list_szone) {
if(pcard && pcard->is_position(POS_FACEUP) && pcard->get_status(STATUS_EFFECT_ENABLED) && code == pcard->get_code()) if(pcard && pcard->is_position(POS_FACEUP) && code == pcard->get_code())
ret = 1; ret = 1;
} }
} }
if(playerid == 1 || playerid == PLAYER_ALL) { if(playerid == 1 || playerid == PLAYER_ALL) {
for(auto& pcard : pduel->game_field->player[1].list_szone) { for(auto& pcard : pduel->game_field->player[1].list_szone) {
if(pcard && pcard->is_position(POS_FACEUP) && pcard->get_status(STATUS_EFFECT_ENABLED) && code == pcard->get_code()) if(pcard && pcard->is_position(POS_FACEUP) && code == pcard->get_code())
ret = 1; ret = 1;
} }
} }
...@@ -1199,13 +1199,13 @@ int32 scriptlib::duel_is_environment(lua_State *L) { ...@@ -1199,13 +1199,13 @@ int32 scriptlib::duel_is_environment(lua_State *L) {
if(!ret && (loc & LOCATION_MZONE)) { if(!ret && (loc & LOCATION_MZONE)) {
if(playerid == 0 || playerid == PLAYER_ALL) { if(playerid == 0 || playerid == PLAYER_ALL) {
for(auto& pcard : pduel->game_field->player[0].list_mzone) { for(auto& pcard : pduel->game_field->player[0].list_mzone) {
if(pcard && pcard->is_position(POS_FACEUP) && pcard->get_status(STATUS_EFFECT_ENABLED) && code == pcard->get_code()) if(pcard && pcard->is_position(POS_FACEUP) && code == pcard->get_code())
ret = 1; ret = 1;
} }
} }
if(playerid == 1 || playerid == PLAYER_ALL) { if(playerid == 1 || playerid == PLAYER_ALL) {
for(auto& pcard : pduel->game_field->player[1].list_mzone) { for(auto& pcard : pduel->game_field->player[1].list_mzone) {
if(pcard && pcard->is_position(POS_FACEUP) && pcard->get_status(STATUS_EFFECT_ENABLED) && code == pcard->get_code()) if(pcard && pcard->is_position(POS_FACEUP) && code == pcard->get_code())
ret = 1; ret = 1;
} }
} }
......
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