1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-02 12:33:52 +00:00
lovr/src/luax.h

36 lines
1.4 KiB
C
Raw Normal View History

2017-01-22 02:00:32 +00:00
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
2017-03-11 10:19:33 +00:00
#include "lib/map/map.h"
2017-01-22 02:00:32 +00:00
2017-01-26 10:20:30 +00:00
#pragma once
2017-01-22 02:00:32 +00:00
2017-05-16 17:38:49 +00:00
#define STRINGIFY(x) #x
2017-01-22 02:00:32 +00:00
#define luax_checktype(L, i, T) *(T**) luaL_checkudata(L, i, #T)
2017-05-16 17:38:49 +00:00
#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))
2017-02-18 22:44:52 +00:00
#define luax_newobject(L, T, x) \
2017-01-22 02:00:32 +00:00
T** u = (T**) lua_newuserdata(L, sizeof(T**)); \
2017-02-18 22:44:52 +00:00
luax_registerobject(L, x); \
2017-01-22 02:00:32 +00:00
luaL_getmetatable(L, #T); \
lua_setmetatable(L, -2); \
*u = x;
2017-02-18 22:44:52 +00:00
#define luax_pushtype(L, T, x) if (!luax_getobject(L, x)) { luax_newobject(L, T, x); }
2017-01-22 02:00:32 +00:00
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);
2017-05-16 17:38:49 +00:00
void luax_extendtype(lua_State* L, const char* base, const char* name, const luaL_Reg* functions);
2017-01-22 02:00:32 +00:00
int luax_releasetype(lua_State* L);
2017-02-18 22:44:52 +00:00
int luax_getobject(lua_State* L, void* object);
void luax_registerobject(lua_State* L, void* object);
2017-01-22 02:00:32 +00:00
void luax_pushenum(lua_State* L, map_int_t* map, int value);
void* luax_checkenum(lua_State* L, int index, map_int_t* map, const char* typeName);
void* luax_optenum(lua_State* L, int index, const char* fallback, map_int_t* map, const char* typeName);