Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
ygopro-core
Commits
d6cdaf55
Commit
d6cdaf55
authored
May 16, 2021
by
mercury233
Committed by
GitHub
May 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check lua stack before pushing (#378)
parent
e52629db
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
interpreter.cpp
interpreter.cpp
+19
-0
No files found.
interpreter.cpp
View file @
d6cdaf55
...
...
@@ -47,6 +47,8 @@ interpreter::~interpreter() {
}
int32
interpreter
::
register_card
(
card
*
pcard
)
{
//create a card in by userdata
luaL_checkstack
(
lua_state
,
1
,
NULL
);
luaL_checkstack
(
current_state
,
1
,
NULL
);
card
**
ppcard
=
(
card
**
)
lua_newuserdata
(
lua_state
,
sizeof
(
card
*
));
*
ppcard
=
pcard
;
pcard
->
ref_handle
=
luaL_ref
(
lua_state
,
LUA_REGISTRYINDEX
);
...
...
@@ -74,6 +76,7 @@ void interpreter::register_effect(effect *peffect) {
if
(
!
peffect
)
return
;
//create a effect in by userdata
luaL_checkstack
(
lua_state
,
3
,
NULL
);
effect
**
ppeffect
=
(
effect
**
)
lua_newuserdata
(
lua_state
,
sizeof
(
effect
*
));
*
ppeffect
=
peffect
;
peffect
->
ref_handle
=
luaL_ref
(
lua_state
,
LUA_REGISTRYINDEX
);
...
...
@@ -103,6 +106,7 @@ void interpreter::register_group(group *pgroup) {
if
(
!
pgroup
)
return
;
//create a group in by userdata
luaL_checkstack
(
lua_state
,
3
,
NULL
);
group
**
ppgroup
=
(
group
**
)
lua_newuserdata
(
lua_state
,
sizeof
(
group
*
));
*
ppgroup
=
pgroup
;
pgroup
->
ref_handle
=
luaL_ref
(
lua_state
,
LUA_REGISTRYINDEX
);
...
...
@@ -138,9 +142,11 @@ int32 interpreter::load_script(const char* script_name) {
int32
interpreter
::
load_card_script
(
uint32
code
)
{
char
class_name
[
20
];
sprintf
(
class_name
,
"c%d"
,
code
);
luaL_checkstack
(
current_state
,
1
,
NULL
);
lua_getglobal
(
current_state
,
class_name
);
//if script is not loaded, create and load it
if
(
lua_isnil
(
current_state
,
-
1
))
{
luaL_checkstack
(
current_state
,
5
,
NULL
);
lua_pop
(
current_state
,
1
);
//create a table & set metatable
lua_createtable
(
current_state
,
0
,
0
);
...
...
@@ -174,6 +180,7 @@ void interpreter::add_param(ptr param, int32 type, bool front) {
void
interpreter
::
push_param
(
lua_State
*
L
,
bool
is_coroutine
)
{
int32
pushed
=
0
;
for
(
const
auto
&
it
:
params
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
uint32
type
=
it
.
second
;
switch
(
type
)
{
case
PARAM_TYPE_INT
:
...
...
@@ -283,6 +290,7 @@ int32 interpreter::call_card_function(card* pcard, const char* f, uint32 param_c
return
OPERATION_FAIL
;
}
card2value
(
current_state
,
pcard
);
luaL_checkstack
(
current_state
,
1
,
NULL
);
lua_getfield
(
current_state
,
-
1
,
f
);
if
(
!
lua_isfunction
(
current_state
,
-
1
))
{
sprintf
(
pduel
->
strbuffer
,
"
\"
CallCardFunction
\"
(c%d.%s): attempt to call an error function"
,
pcard
->
data
.
code
,
f
);
...
...
@@ -323,6 +331,7 @@ int32 interpreter::call_code_function(uint32 code, const char* f, uint32 param_c
return
OPERATION_FAIL
;
}
load_card_script
(
code
);
luaL_checkstack
(
current_state
,
1
,
NULL
);
lua_getfield
(
current_state
,
-
1
,
f
);
if
(
!
lua_isfunction
(
current_state
,
-
1
))
{
sprintf
(
pduel
->
strbuffer
,
"
\"
CallCodeFunction
\"
: attempt to call an error function"
);
...
...
@@ -386,6 +395,7 @@ int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) {
return
TRUE
;
no_action
++
;
call_depth
++
;
luaL_checkstack
(
current_state
,
1
+
extraargs
,
NULL
);
lua_pushvalue
(
current_state
,
findex
);
interpreter
::
card2value
(
current_state
,
pcard
);
for
(
int32
i
=
0
;
i
<
extraargs
;
++
i
)
...
...
@@ -417,6 +427,7 @@ int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraarg
return
0
;
no_action
++
;
call_depth
++
;
luaL_checkstack
(
current_state
,
1
+
extraargs
,
NULL
);
lua_pushvalue
(
current_state
,
findex
);
interpreter
::
card2value
(
current_state
,
pcard
);
for
(
int32
i
=
0
;
i
<
extraargs
;
++
i
)
...
...
@@ -579,6 +590,7 @@ int32 interpreter::call_coroutine(int32 f, uint32 param_count, uint32 * yield_va
}
}
int32
interpreter
::
clone_function_ref
(
int32
func_ref
)
{
luaL_checkstack
(
current_state
,
1
,
NULL
);
lua_rawgeti
(
current_state
,
LUA_REGISTRYINDEX
,
func_ref
);
int32
ref
=
luaL_ref
(
current_state
,
LUA_REGISTRYINDEX
);
return
ref
;
...
...
@@ -586,6 +598,7 @@ int32 interpreter::clone_function_ref(int32 func_ref) {
void
*
interpreter
::
get_ref_object
(
int32
ref_handler
)
{
if
(
ref_handler
==
0
)
return
nullptr
;
luaL_checkstack
(
current_state
,
1
,
NULL
);
lua_rawgeti
(
current_state
,
LUA_REGISTRYINDEX
,
ref_handler
);
void
*
p
=
*
(
void
**
)
lua_touserdata
(
current_state
,
-
1
);
lua_pop
(
current_state
,
1
);
...
...
@@ -593,30 +606,35 @@ void* interpreter::get_ref_object(int32 ref_handler) {
}
//Convert a pointer to a lua value, +1 -0
void
interpreter
::
card2value
(
lua_State
*
L
,
card
*
pcard
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
if
(
!
pcard
||
pcard
->
ref_handle
==
0
)
lua_pushnil
(
L
);
else
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
pcard
->
ref_handle
);
}
void
interpreter
::
group2value
(
lua_State
*
L
,
group
*
pgroup
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
if
(
!
pgroup
||
pgroup
->
ref_handle
==
0
)
lua_pushnil
(
L
);
else
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
pgroup
->
ref_handle
);
}
void
interpreter
::
effect2value
(
lua_State
*
L
,
effect
*
peffect
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
if
(
!
peffect
||
peffect
->
ref_handle
==
0
)
lua_pushnil
(
L
);
else
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
peffect
->
ref_handle
);
}
void
interpreter
::
function2value
(
lua_State
*
L
,
int32
func_ref
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
if
(
!
func_ref
)
lua_pushnil
(
L
);
else
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
func_ref
);
}
int32
interpreter
::
get_function_handle
(
lua_State
*
L
,
int32
index
)
{
luaL_checkstack
(
L
,
1
,
NULL
);
lua_pushvalue
(
L
,
index
);
int32
ref
=
luaL_ref
(
L
,
LUA_REGISTRYINDEX
);
return
ref
;
...
...
@@ -626,6 +644,7 @@ void interpreter::set_duel_info(lua_State* L, duel* 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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment