Files
yugioh-legacy-engine/core/scriptlib.cpp
T
donnyandClaude Fable 5.1 26f9baf9b4 core: import the rules core (ygopro-core 973672dc + fork patches)
The vendored ocgcore from the Unity repo (Tools/YGOLegacy/ocgcore at dev
HEAD). Upstream is nanahira/ygopro-core at 973672dc9ce7cb49f47173277ab1ad0e318b7593;
the seven files that differ from it carry the fork's core patches, already
applied: 0001 face-down Token setcode, 0004 effect damage step outside a
chain, 0008 Sandbox god mode, 0015 tag first seat holds the hand, 0022
attack preview, 0024 attack preview legality. Generated build/ output is
left out.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-14 20:58:16 -07:00

84 lines
2.1 KiB
C++

/*
* scriptlib.cpp
*
* Created on: 2010-7-29
* Author: Argon
*/
#include "scriptlib.h"
#include "duel.h"
static int32_t check_data_type(lua_State* L, int32_t index, const char* tname) {
luaL_checkstack(L, 2, nullptr);
int32_t result = FALSE;
if(lua_getmetatable(L, index)) {
lua_getglobal(L, tname);
if(lua_rawequal(L, -1, -2))
result = TRUE;
lua_pop(L, 2);
}
return result;
}
int32_t scriptlib::check_param(lua_State* L, int32_t param_type, int32_t index, int32_t retfalse) {
switch (param_type) {
case PARAM_TYPE_CARD: {
luaL_checkstack(L, 1, nullptr);
int32_t result = FALSE;
if(lua_isuserdata(L, index) && lua_getmetatable(L, index)) {
result = check_data_type(L, -1, "Card");
lua_pop(L, 1);
}
if(result)
return TRUE;
if(retfalse)
return FALSE;
return luaL_error(L, "Parameter %d should be \"Card\".", index);
break;
}
case PARAM_TYPE_GROUP: {
if(lua_isuserdata(L, index) && check_data_type(L, index, "Group"))
return TRUE;
if(retfalse)
return FALSE;
return luaL_error(L, "Parameter %d should be \"Group\".", index);
break;
}
case PARAM_TYPE_EFFECT: {
if(lua_isuserdata(L, index) && check_data_type(L, index, "Effect"))
return TRUE;
if(retfalse)
return FALSE;
return luaL_error(L, "Parameter %d should be \"Effect\".", index);
break;
}
case PARAM_TYPE_FUNCTION: {
if(lua_isfunction(L, index))
return TRUE;
if(retfalse)
return FALSE;
return luaL_error(L, "Parameter %d should be \"Function\".", index);
break;
}
case PARAM_TYPE_STRING: {
if(lua_isstring(L, index))
return TRUE;
if(retfalse)
return FALSE;
return luaL_error(L, "Parameter %d should be \"String\".", index);
break;
}
}
return FALSE;
}
int32_t scriptlib::check_param_count(lua_State* L, int32_t count) {
if (lua_gettop(L) < count)
return luaL_error(L, "%d Parameters are needed.", count);
return TRUE;
}
int32_t scriptlib::check_action_permission(lua_State* L) {
duel* pduel = interpreter::get_duel_info(L);
if(pduel->lua->no_action && !pduel->lua->disable_action_check)
return luaL_error(L, "Action is not allowed here.");
return TRUE;
}