terom@143: #ifndef LUA_TYPE_H terom@143: #define LUA_TYPE_H terom@143: terom@143: /** terom@143: * @file terom@143: * terom@143: * Convenience functions for defining "types" in lua terom@143: */ terom@143: #include terom@143: terom@143: // XXX: remove terom@143: #include terom@143: terom@143: /** terom@145: * A type's method terom@145: * terom@145: * XXX: a name field? terom@143: */ terom@145: struct lua_method { terom@145: /** The name of the method */ terom@145: const char *name; terom@143: terom@145: /** The function pointer */ terom@145: lua_CFunction func; terom@145: terom@145: /** The function definition, optional */ terom@145: const struct lua_func *info; terom@145: }; terom@145: terom@145: #define LUA_METHOD(name, func, info) \ terom@145: { (name), (func), (info) } terom@145: terom@145: #define LUA_METHODS(...) \ terom@145: { __VA_ARGS__, { NULL, NULL, NULL } } terom@143: terom@143: /** terom@145: * A type terom@143: */ terom@145: struct lua_type { terom@145: /** The name of the type */ terom@145: const char *name; terom@145: }; terom@145: terom@145: #define LUA_TYPE(name) \ terom@145: { (name) } terom@143: terom@143: /** terom@145: * Register a new metadata table for the given type in the given lua state. terom@145: * terom@145: * This leaves the new type (metatable) on the stack. terom@143: */ terom@145: void lua_type_register (lua_State *L, const struct lua_type *type, const struct lua_method methods[]); terom@145: terom@145: /** terom@145: * Create a new instance of the given type. terom@145: * terom@145: * This leaves the new userdata object on the stack. terom@145: */ terom@145: void* lua_type_create (lua_State *L, const struct lua_type *type, size_t size); terom@145: terom@145: /** terom@145: * Create a new userdata type, and also create an instance of it, register it as a global, and return it. terom@145: * terom@145: * This leaves the new userdata object on the stack. terom@145: */ terom@145: void* lua_type_register_global (lua_State *L, const struct lua_type *type, const struct lua_method methods[], terom@145: const char *global_name, size_t size); terom@145: terom@145: /** terom@145: * Get an object of the given type from the given stack position terom@145: */ terom@145: void* lua_type_get (lua_State *L, const struct lua_type *type, int index); terom@143: terom@143: #endif