Skip to content

Commit

Permalink
Add lua_isvector, luaL_checkvector and luaL_optvector
Browse files Browse the repository at this point in the history
  • Loading branch information
Petri Häkkinen committed Dec 1, 2021
1 parent 35e497b commit 69bacee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions VM/include/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ LUA_API int lua_isstring(lua_State* L, int idx);
LUA_API int lua_iscfunction(lua_State* L, int idx);
LUA_API int lua_isLfunction(lua_State* L, int idx);
LUA_API int lua_isuserdata(lua_State* L, int idx);
LUA_API int lua_isvector(lua_State* L, int idx);
LUA_API int lua_type(lua_State* L, int idx);
LUA_API const char* lua_typename(lua_State* L, int tp);

Expand Down
3 changes: 3 additions & 0 deletions VM/include/lualib.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ LUALIB_API int luaL_optinteger(lua_State* L, int nArg, int def);
LUALIB_API unsigned luaL_checkunsigned(lua_State* L, int numArg);
LUALIB_API unsigned luaL_optunsigned(lua_State* L, int numArg, unsigned def);

LUALIB_API const float* luaL_checkvector(lua_State* L, int narg);
LUALIB_API const float* luaL_optvector(lua_State* L, int narg, const float* def);

LUALIB_API void luaL_checkstack(lua_State* L, int sz, const char* msg);
LUALIB_API void luaL_checktype(lua_State* L, int narg, int t);
LUALIB_API void luaL_checkany(lua_State* L, int narg);
Expand Down
6 changes: 6 additions & 0 deletions VM/src/lapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ int lua_isuserdata(lua_State* L, int idx)
return (ttisuserdata(o) || ttislightuserdata(o));
}

int lua_isvector(lua_State* L, int idx)
{
const TValue* o = index2adr(L, idx);
return ttisvector(o);
}

int lua_rawequal(lua_State* L, int index1, int index2)
{
StkId o1 = index2adr(L, index1);
Expand Down
13 changes: 13 additions & 0 deletions VM/src/laux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ unsigned luaL_optunsigned(lua_State* L, int narg, unsigned def)
return luaL_opt(L, luaL_checkunsigned, narg, def);
}

const float* luaL_checkvector(lua_State* L, int narg)
{
const float* v = lua_tovector(L, narg);
if (!v)
tag_error(L, narg, LUA_TVECTOR);
return v;
}

const float* luaL_optvector(lua_State* L, int narg, const float* def)
{
return luaL_opt(L, luaL_checkvector, narg, def);
}

int luaL_getmetafield(lua_State* L, int obj, const char* event)
{
if (!lua_getmetatable(L, obj)) /* no metatable? */
Expand Down

0 comments on commit 69bacee

Please sign in to comment.