- /** lg2d PhysicalWorld class.
- * Represents a "world" in which all physical objects exist. Used internally by
- * the Scene class.
- */
- #include <Box2D/Box2D.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <lua5.1/lua.h>
- #include <lua5.1/lauxlib.h>
- #include <lua5.1/lualib.h>
- #include <string.h>
- //Prefix of all Lua registry table keys to prevent collision with libraries
- #define __s(x) _s(x)
- #define _s(x) #x
- #define LUA_REGISTRY_PREFIX "LG2D" LUANAME ":"
- /* Convenient macros. */
- /* see http://tinyurl.com/42mood if you don't understand while(0). */
- #define EXPORT_FUNC(f) {#f, Lua_PhysicalWorld_##f}
- #define LUA_FUNC_NAME(f) Lua_PhysicalWorld_##f
- #define LUA_FUNC(f) static int Lua_PhysicalWorld_##f(lua_State *Lua)
- #define GET_SELF() PhysicalWorld *self = \
- (PhysicalWorld*)((PhysicalWorld **)lua_touserdata(Lua, 1))[0]
- #define GET_PARENT() lua_pushstring(Lua, "parent");\
- lua_rawget(Lua, 1);\
- PhysicalWorld *parent = (PhysicalWorld*)lua_touserdata(Lua, -1);\
- lua_pop(Lua, 1);
- #define LUA_PUSH_TABLE_VALUE(luastate, keytype, key, valtype, val) do {\
- lua_push##keytype((luastate), (key));\
- lua_push##valtype((luastate), (val));\
- lua_settable((luastate), -3);\
- } while(0)
- #define LUA_PUSH_NAMED_OBJECT_FUNC(luastate, funcname, obj, name) do {\
- lua_pushstring((luastate), (#funcname));\
- lua_pushcfunction((luastate), (Lua_##obj##_##name));\
- lua_settable((luastate), -3);\
- } while(0)
- #define LUA_RETURN_ERRMSG(luastate, message) do {\
- /* DebugOut(DO_ALL, "%s:%d: LUA_PUSH_ERRMSG: %s\n", __FILE__, __LINE__, (message));\ */\
- lua_pushnil((luastate));\
- lua_pushstring((luastate), (message));\
- return 2;\
- } while(0)
- #define LUA_RETURN_ERRMSGF(luastate, ...) do {\
- lua_pushnil((luastate));\
- lua_pushfstring((luastate), __VA_ARGS__);\
- return 2;\
- } while(0)
- #define LUA_RETURN_NIL(luastate) do {\
- lua_pushnil(luastate);\
- return 1;\
- } while(0)
- /*
- #ifdef __cplusplus
- }
- #endif */
- class PhysicalWorld {
- public:
- static void GetRefsTable(lua_State *Lua);
- PhysicalWorld(lua_State *Lua);
- ~PhysicalWorld();
- //Lua metamethods
- int __index(lua_State *Lua);
- //variables accessible to Lua. note that each instance also functions
- //like a table; arbitrary values can be stored in it.
- protected:
- lua_State *Lua;
- b2World *World;
- private:
- };
- /* #ifdef __cplusplus
- extern "C" {
- #endif */
- /** Function prototypes.
- */
- LUA_FUNC(Create);
- LUA_FUNC(Meta_index);
- LUA_FUNC(Meta_newindex);
- LUA_FUNC(Meta_gc);
- LUALIB_API int LUAOPENFUNC (lua_State *Lua);
- #ifdef __cplusplus
- }
- #endif