mirror of https://github.com/bjornbytes/lovr.git
luax_extendtype; luax_checktypeof;
This commit is contained in:
parent
1115929583
commit
4ac72a54d6
10
src/luax.c
10
src/luax.c
|
@ -71,6 +71,16 @@ void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions
|
|||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
void luax_extendtype(lua_State* L, const char* base, const char* name, const luaL_Reg* functions) {
|
||||
luax_registertype(L, name, functions);
|
||||
luaL_getmetatable(L, name);
|
||||
|
||||
lua_pushstring(L, base);
|
||||
lua_setfield(L, -2, "super");
|
||||
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
int luax_releasetype(lua_State* L) {
|
||||
lovrRelease(*(Ref**) lua_touserdata(L, 1));
|
||||
return 0;
|
||||
|
|
11
src/luax.h
11
src/luax.h
|
@ -5,7 +5,17 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#define STRINGIFY(x) #x
|
||||
|
||||
#define luax_checktype(L, i, T) *(T**) luaL_checkudata(L, i, #T)
|
||||
#define luax_checktypeof(L, i, T) \
|
||||
*(T**) (luaL_argcheck(L, lua_touserdata(L, i), i, "Expected " STRINGIFY(T)), \
|
||||
lua_getmetatable(L, i), \
|
||||
lua_getfield(L, -1, "super"), \
|
||||
lua_pushstring(L, #T), \
|
||||
luaL_argcheck(L, lua_equal(L, -1, -2), i, "Expected " STRINGIFY(T)), \
|
||||
lua_pop(L, 3), \
|
||||
lua_touserdata(L, i))
|
||||
#define luax_newobject(L, T, x) \
|
||||
T** u = (T**) lua_newuserdata(L, sizeof(T**)); \
|
||||
luax_registerobject(L, x); \
|
||||
|
@ -16,6 +26,7 @@
|
|||
|
||||
int luax_preloadmodule(lua_State* L, const char* key, lua_CFunction f);
|
||||
void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions);
|
||||
void luax_extendtype(lua_State* L, const char* base, const char* name, const luaL_Reg* functions);
|
||||
int luax_releasetype(lua_State* L);
|
||||
int luax_getobject(lua_State* L, void* object);
|
||||
void luax_registerobject(lua_State* L, void* object);
|
||||
|
|
Loading…
Reference in New Issue