From 69bacee4d466d6e231d41353d821533d37394858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petri=20H=C3=A4kkinen?= Date: Wed, 1 Dec 2021 10:09:11 +0200 Subject: [PATCH] Add lua_isvector, luaL_checkvector and luaL_optvector --- VM/include/lua.h | 1 + VM/include/lualib.h | 3 +++ VM/src/lapi.cpp | 6 ++++++ VM/src/laux.cpp | 13 +++++++++++++ 4 files changed, 23 insertions(+) diff --git a/VM/include/lua.h b/VM/include/lua.h index a2c722135..3f0d8aea2 100644 --- a/VM/include/lua.h +++ b/VM/include/lua.h @@ -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); diff --git a/VM/include/lualib.h b/VM/include/lualib.h index 54b008ffb..baf27b47e 100644 --- a/VM/include/lualib.h +++ b/VM/include/lualib.h @@ -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); diff --git a/VM/src/lapi.cpp b/VM/src/lapi.cpp index 3f4c0fd6e..534a060a5 100644 --- a/VM/src/lapi.cpp +++ b/VM/src/lapi.cpp @@ -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); diff --git a/VM/src/laux.cpp b/VM/src/laux.cpp index a5e54358d..7ed2a62ee 100644 --- a/VM/src/laux.cpp +++ b/VM/src/laux.cpp @@ -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? */