1 // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
23 #define LUABIND_BUILDING
25 #include <luabind/lua_include.hpp>
27 #include <luabind/luabind.hpp>
28 #include <luabind/function.hpp>
35 int make_property(lua_State
* L
)
37 int args
= lua_gettop(L
);
39 if (args
== 0 || args
> 2)
41 lua_pushstring(L
, "make_property() called with wrong number of arguments.");
48 lua_pushcclosure(L
, &detail::property_tag
, 2);
52 } // namespace unnamed
54 void open(lua_State
* L
)
56 // get the global class registry, or create one if it doesn't exist
57 // (it's global within a lua state)
58 detail::class_registry
* r
= 0;
60 // If you hit this assert it's because you have called luabind::open()
61 // twice on the same lua_State.
62 assert((detail::class_registry::get_registry(L
) == 0)
63 && "you cannot call luabind::open() twice");
65 lua_pushstring(L
, "__luabind_classes");
66 r
= static_cast<detail::class_registry
*>(
67 lua_newuserdata(L
, sizeof(detail::class_registry
)));
71 lua_pushstring(L
, "__gc");
74 , detail::garbage_collector_s
<
75 detail::class_registry
80 lua_setmetatable(L
, -2);
82 new(r
) detail::class_registry(L
);
83 lua_settable(L
, LUA_REGISTRYINDEX
);
86 lua_pushstring(L
, "__luabind_class_id_map");
87 void* classes_storage
= lua_newuserdata(L
, sizeof(detail::class_id_map
));
88 detail::class_id_map
* class_ids
= new (classes_storage
) detail::class_id_map
;
90 lua_settable(L
, LUA_REGISTRYINDEX
);
92 lua_pushstring(L
, "__luabind_cast_graph");
93 void* cast_graph_storage
= lua_newuserdata(
94 L
, sizeof(detail::cast_graph
));
95 detail::cast_graph
* graph
= new (cast_graph_storage
) detail::cast_graph
;
97 lua_settable(L
, LUA_REGISTRYINDEX
);
99 lua_pushstring(L
, "__luabind_class_map");
100 void* class_map_storage
= lua_newuserdata(
101 L
, sizeof(detail::class_map
));
102 detail::class_map
* classes
= new (class_map_storage
) detail::class_map
;
104 lua_settable(L
, LUA_REGISTRYINDEX
);
106 // add functions (class, cast etc...)
107 lua_pushstring(L
, "class");
108 lua_pushcclosure(L
, detail::create_class::stage1
, 0);
109 lua_settable(L
, LUA_GLOBALSINDEX
);
111 lua_pushstring(L
, "property");
112 lua_pushcclosure(L
, &make_property
, 0);
113 lua_settable(L
, LUA_GLOBALSINDEX
);
116 } // namespace luabind