| 28 | namespace luabind { |
| 29 | |
| 30 | void open(lua_State* L) |
| 31 | { |
| 32 | // get the global class registry, or create one if it doesn't exist |
| 33 | // (it's global within a lua state) |
| 34 | detail::class_registry* r = 0; |
| 35 | |
| 36 | // If you hit this assert it's because you have called luabind::open() |
| 37 | // twice on the same lua_State. |
| 38 | assert((detail::class_registry::get_registry(L) == 0) |
| 39 | && "you cannot call luabind::open() twice"); |
| 40 | |
| 41 | lua_pushstring(L, "__luabind_classes"); |
| 42 | r = static_cast<detail::class_registry*>( |
| 43 | lua_newuserdata(L, sizeof(detail::class_registry))); |
| 44 | |
| 45 | // set gc metatable |
| 46 | lua_newtable(L); |
| 47 | lua_pushstring(L, "__gc"); |
| 48 | lua_pushcclosure( |
| 49 | L |
| 50 | , detail::garbage_collector_s< |
| 51 | detail::class_registry |
| 52 | >::apply |
| 53 | , 0); |
| 54 | |
| 55 | lua_settable(L, -3); |
| 56 | lua_setmetatable(L, -2); |
| 57 | |
| 58 | new(r) detail::class_registry(L); |
| 59 | lua_settable(L, LUA_REGISTRYINDEX); |
| 60 | |
| 61 | // add functions (class, cast etc...) |
| 62 | lua_pushstring(L, "class"); |
| 63 | lua_pushcclosure(L, detail::create_class::stage1, 0); |
| 64 | lua_settable(L, LUA_GLOBALSINDEX); |
| 65 | } |
| 66 | |
| 67 | } // namespace luabind |
| 68 |
no test coverage detected