2 #ifndef UGDK_SCRIPT_LUA_PRIMITIVE_H_
3 #define UGDK_SCRIPT_LUA_PRIMITIVE_H_
11 #define CHECK_LUA_TYPE(name, type) (defined name) && (name == type)
14 #define LUA_OPNAME(name) lua_##name
24 #define DEFINE_LUA_PRIMITIVE_OP(name) \
26 class LUA_OPNAME(name) { \
28 LUA_OPNAME(name)() {} \
32 #define DEFINE_LUA_PRIMITIVE_OPCASE(name, partial, type, ret, arg, exp) \
34 class LUA_OPNAME(name)<type> { \
36 static ret primitive(lua_State* L, arg) { \
40 LUA_OPNAME(name)() {} \
49 #define DEFINE_LUA_PARTIAL_PUSH(partial, type, call) \
50 DEFINE_LUA_PRIMITIVE_OPCASE(push, partial, type, void, type val, call)
52 #define DEFINE_LUA_FULL_PUSH(type, call) \
53 DEFINE_LUA_PARTIAL_PUSH(, type, call)
55 #define DEFINE_LUA_SIMPLE_PUSH(type, name) \
56 DEFINE_LUA_FULL_PUSH(type, lua_push##name(L, val))
67 #undef DEFINE_LUA_PARTIAL_PUSH
68 #undef DEFINE_LUA_FULL_PUSH
69 #undef DEFINE_LUA_SIMPLE_PUSH
80 #define DEFINE_LUA_TO(type, call) \
81 DEFINE_LUA_PRIMITIVE_OPCASE(to, , type, type, int index, return (call))
83 #define DEFINE_LUA_SIMPLE_TO(type, name) \
84 DEFINE_LUA_TO(type, static_cast<type>(lua_to##name(L, index)))
93 #undef DEFINE_LUA_SIMPLE_TO
104 #define DEFINE_LUA_IS(type, check) \
105 DEFINE_LUA_PRIMITIVE_OPCASE(is, , type, bool, int index, return !!(check))
107 #define DEFINE_LUA_SIMPLE_IS(type, name) \
108 DEFINE_LUA_IS(type, lua_is##name(L, index))
116 #undef DEFINE_LUA_SIMPLE_IS
DEFINE_LUA_IS(bool,!lua_isnone(L, index))
Definition: animation.h:11
DEFINE_LUA_SIMPLE_PUSH(const char *, string)
DEFINE_LUA_FULL_PUSH(lua_CFunction, lua_pushcclosure(L, val, 0))
DEFINE_LUA_TO(const char *, lua_tolstring(L, index, nullptr))
DEFINE_LUA_PRIMITIVE_OP(push)
DEFINE_LUA_SIMPLE_TO(int, integer)
int(* lua_CFunction)(lua_State *)
Definition: defs.h:9
DEFINE_LUA_PARTIAL_PUSH(class T, T *, lua_pushlightuserdata(L, AsUData< T >(val)))
void * UData
Definition: defs.h:23
DEFINE_LUA_SIMPLE_IS(const char *, string)