Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
b1d318de
Unverified
Commit
b1d318de
authored
Dec 24, 2020
by
Nathaniel Wesley Filardo
Committed by
GitHub
Dec 24, 2020
Browse files
NFC: Backport luaL_testudata to Lua 5.1 (#3352)
And move luaL_checkudata to it, as in 5.3.
parent
9c1f4aca
Changes
2
Show whitespace changes
Inline
Side-by-side
app/lua/lauxlib.c
View file @
b1d318de
...
...
@@ -285,21 +285,25 @@ LUALIB_API int luaL_rometatable (lua_State *L, const char* tname, const ROTable
return
1
;
}
LUALIB_API
void
*
luaL_
check
udata
(
lua_State
*
L
,
int
ud
,
const
char
*
tname
)
{
LUALIB_API
void
*
luaL_
test
udata
(
lua_State
*
L
,
int
ud
,
const
char
*
tname
)
{
void
*
p
=
lua_touserdata
(
L
,
ud
);
if
(
p
!=
NULL
)
{
/* value is a userdata? */
if
(
lua_getmetatable
(
L
,
ud
))
{
/* does it have a metatable? */
lua_getfield
(
L
,
LUA_REGISTRYINDEX
,
tname
);
/* get correct metatable */
if
(
lua_rawequal
(
L
,
-
1
,
-
2
))
{
/* does it have the correct mt? */
if
(
!
lua_rawequal
(
L
,
-
1
,
-
2
))
/* not the same? */
p
=
NULL
;
/* value is a userdata with wrong metatable */
lua_pop
(
L
,
2
);
/* remove both metatables */
return
p
;
}
}
}
luaL_typerror
(
L
,
ud
,
tname
);
/* else error */
return
NULL
;
/* to avoid warnings */
return
NULL
;
/* value is not a userdata with a metatable */
}
LUALIB_API
void
*
luaL_checkudata
(
lua_State
*
L
,
int
ud
,
const
char
*
tname
)
{
void
*
p
=
luaL_testudata
(
L
,
ud
,
tname
);
if
(
p
==
NULL
)
luaL_typerror
(
L
,
ud
,
tname
);
return
p
;
}
LUALIB_API
void
luaL_checkstack
(
lua_State
*
L
,
int
space
,
const
char
*
mes
)
{
if
(
!
lua_checkstack
(
L
,
space
))
...
...
app/lua/lauxlib.h
View file @
b1d318de
...
...
@@ -66,6 +66,7 @@ LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
LUALIB_API
int
(
luaL_newmetatable
)
(
lua_State
*
L
,
const
char
*
tname
);
LUALIB_API
int
(
luaL_rometatable
)
(
lua_State
*
L
,
const
char
*
tname
,
const
ROTable
*
p
);
LUALIB_API
void
*
(
luaL_testudata
)
(
lua_State
*
L
,
int
ud
,
const
char
*
tname
);
LUALIB_API
void
*
(
luaL_checkudata
)
(
lua_State
*
L
,
int
ud
,
const
char
*
tname
);
LUALIB_API
void
(
luaL_where
)
(
lua_State
*
L
,
int
lvl
);
...
...
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