MINOR: lua: merge function
This patch merges the last imported functions in one, because the function hlua_metatype is only used by hlua_checudata. This patch fix also the compilation error became by the copy of the code.
This commit is contained in:
parent
9e7e3ea991
commit
5351827560
@ -9,43 +9,40 @@
|
|||||||
|
|
||||||
#include <common/time.h>
|
#include <common/time.h>
|
||||||
|
|
||||||
/* Return true if the data in stack[<ud>] is an object of
|
|
||||||
* type <class_ref>.
|
|
||||||
*/
|
|
||||||
static int hlua_metaistype(lua_State *L, int ud, int class_ref)
|
|
||||||
{
|
|
||||||
if (!lua_getmetatable(L, ud))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, class_ref);
|
|
||||||
if (!lua_rawequal(L, -1, -2)) {
|
|
||||||
lua_pop(L, 2);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
lua_pop(L, 2);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return an object of the expected type, or throws an error. */
|
/* Return an object of the expected type, or throws an error. */
|
||||||
void *hlua_checkudata(lua_State *L, int ud, int class_ref)
|
void *hlua_checkudata(lua_State *L, int ud, int class_ref)
|
||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Check if the stack entry is an array. */
|
/* Check if the stack entry is an array. */
|
||||||
if (!lua_istable(L, ud))
|
if (!lua_istable(L, ud))
|
||||||
WILL_LJMP(luaL_argerror(L, ud, NULL));
|
luaL_argerror(L, ud, NULL);
|
||||||
|
|
||||||
|
/* pop the metatable of the referencecd object. */
|
||||||
|
if (!lua_getmetatable(L, ud))
|
||||||
|
luaL_argerror(L, ud, NULL);
|
||||||
|
|
||||||
|
/* pop the expected metatable. */
|
||||||
|
lua_rawgeti(L, LUA_REGISTRYINDEX, class_ref);
|
||||||
|
|
||||||
/* Check if the metadata have the expected type. */
|
/* Check if the metadata have the expected type. */
|
||||||
if (!hlua_metaistype(L, ud, class_ref))
|
ret = lua_rawequal(L, -1, -2);
|
||||||
WILL_LJMP(luaL_argerror(L, ud, NULL));
|
lua_pop(L, 2);
|
||||||
|
if (!ret)
|
||||||
|
luaL_argerror(L, ud, NULL);
|
||||||
|
|
||||||
/* Push on the stack at the entry [0] of the table. */
|
/* Push on the stack at the entry [0] of the table. */
|
||||||
lua_rawgeti(L, ud, 0);
|
lua_rawgeti(L, ud, 0);
|
||||||
|
|
||||||
/* Check if this entry is userdata. */
|
/* Check if this entry is userdata. */
|
||||||
p = lua_touserdata(L, -1);
|
p = lua_touserdata(L, -1);
|
||||||
if (!p)
|
if (!p)
|
||||||
WILL_LJMP(luaL_argerror(L, ud, NULL));
|
luaL_argerror(L, ud, NULL);
|
||||||
|
|
||||||
/* Remove the entry returned by lua_rawgeti(). */
|
/* Remove the entry returned by lua_rawgeti(). */
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
/* Return the associated struct. */
|
/* Return the associated struct. */
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user