MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / create_cpp_class_metatable

Function create_cpp_class_metatable

Source/Misc/luabind/src/class_registry.cpp:44–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42 namespace {
43
44 int create_cpp_class_metatable(lua_State* L)
45 {
46 lua_createtable(L, 0, 7);
47
48 // mark the table with our unique tag
49 // that says that the user data that has this
50 // metatable is a class_rep
51 lua_pushboolean(L, true);
52 lua_rawsetp(L, -2, &classrep_tag);
53
54 lua_pushliteral(L, "__gc");
55 lua_pushcfunction(L, &garbage_collector<class_rep>);
56 lua_rawset(L, -3);
57
58 lua_pushliteral(L, "__call");
59 lua_pushcfunction(L, &class_rep::constructor_dispatcher);
60 lua_rawset(L, -3);
61
62 lua_pushliteral(L, "__index");
63 lua_pushcfunction(L, &class_rep::static_class_gettable);
64 lua_rawset(L, -3);
65
66 lua_pushliteral(L, "__newindex");
67 lua_pushcfunction(L, &class_rep::lua_settable_dispatcher);
68 lua_rawset(L, -3);
69
70 lua_pushliteral(L, "__tostring");
71 lua_pushcfunction(L, &class_rep::tostring);
72 lua_rawset(L, -3);
73
74 // Direct calls to metamethods cannot be allowed, because the
75 // callee trusts the caller to pass arguments of the right type.
76 lua_pushliteral(L, "__metatable");
77 lua_pushboolean(L, true);
78 lua_rawset(L, -3);
79
80 return luaL_ref(L, LUA_REGISTRYINDEX);
81 }
82
83 int create_lua_class_metatable(lua_State* L)
84 {

Callers 2

class_registryMethod · 0.85

Calls 5

lua_createtableFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_rawsetpFunction · 0.85
lua_rawsetFunction · 0.85
luaL_refFunction · 0.85

Tested by

no test coverage detected