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-10-21 20:10:07 +00:00
|
|
|
#include "util.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
|
|
|
|
|
2018-01-21 23:32:03 +00:00
|
|
|
#define luax_totype(L, i, T) (luax_testudata(L, i, #T))
|
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), \
|
2017-12-10 03:11:53 +00:00
|
|
|
lua_getfield(L, -1, "name"), \
|
|
|
|
lua_getfield(L, -2, "super"), \
|
2017-05-16 17:38:49 +00:00
|
|
|
lua_pushstring(L, #T), \
|
2017-12-10 03:11:53 +00:00
|
|
|
luaL_argcheck(L, lua_equal(L, -1, -2) || lua_equal(L, -1, -3), i, "Expected " STRINGIFY(T)), \
|
|
|
|
lua_pop(L, 4), \
|
2017-05-16 17:38:49 +00:00
|
|
|
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-05-17 21:45:24 +00:00
|
|
|
#define luax_pushtype(L, T, x) \
|
|
|
|
if (!x) { lua_pushnil(L); } \
|
|
|
|
else 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);
|
2018-05-13 23:43:15 +00:00
|
|
|
int luax_emptymodule(lua_State* L);
|
2018-07-07 20:54:53 +00:00
|
|
|
void luax_registerloader(lua_State* L, lua_CFunction loader, int index);
|
2017-01-22 02:00:32 +00:00
|
|
|
void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions);
|
2017-05-16 21:37:05 +00:00
|
|
|
void luax_extendtype(lua_State* L, const char* base, const char* name, const luaL_Reg* baseFunctions, const luaL_Reg* functions);
|
2017-01-22 02:00:32 +00:00
|
|
|
int luax_releasetype(lua_State* L);
|
2018-01-21 23:32:03 +00:00
|
|
|
void* luax_testudata(lua_State* L, int index, const char* type);
|
2017-02-18 22:44:52 +00:00
|
|
|
int luax_getobject(lua_State* L, void* object);
|
|
|
|
void luax_registerobject(lua_State* L, void* object);
|
2018-02-17 17:18:08 +00:00
|
|
|
int luax_getstack(lua_State* L);
|
2017-11-23 04:08:46 +00:00
|
|
|
void luax_pushconf(lua_State* L);
|
2018-02-17 17:18:08 +00:00
|
|
|
int luax_setconf(lua_State* L);
|
2017-10-21 20:10:07 +00:00
|
|
|
Color luax_checkcolor(lua_State* L, int index);
|