| 970 | } |
| 971 | |
| 972 | int luabind::detail::class_rep::construct_lua_class_callback(lua_State* L) |
| 973 | { |
| 974 | class_rep* crep = static_cast<class_rep*>(lua_touserdata(L, 1)); |
| 975 | |
| 976 | int args = lua_gettop(L); |
| 977 | |
| 978 | // lua stack: crep <arguments> |
| 979 | |
| 980 | lua_newtable(L); |
| 981 | detail::lua_reference ref; |
| 982 | ref.set(L); |
| 983 | |
| 984 | bool has_bases = !crep->bases().empty(); |
| 985 | |
| 986 | if (has_bases) |
| 987 | { |
| 988 | lua_pushstring(L, "super"); |
| 989 | lua_pushvalue(L, 1); // crep |
| 990 | } |
| 991 | |
| 992 | // lua stack: crep <arguments> "super" crep |
| 993 | // or |
| 994 | // lua stack: crep <arguments> |
| 995 | |
| 996 | // if we have a baseclass we set the flag to say that the super has not yet been called |
| 997 | // we will use this flag later to check that it actually was called from __init() |
| 998 | int flags = object_rep::lua_class | object_rep::owner | (has_bases ? object_rep::call_super : 0); |
| 999 | |
| 1000 | // void* obj_ptr = lua_newuserdata(L, sizeof(object_rep)); |
| 1001 | void* obj_ptr; |
| 1002 | void* held_storage; |
| 1003 | |
| 1004 | std::tie(obj_ptr, held_storage) = crep->allocate(L); |
| 1005 | (new(obj_ptr) object_rep(crep, flags, ref))->set_object(held_storage); |
| 1006 | |
| 1007 | detail::getref(L, crep->metatable_ref()); |
| 1008 | lua_setmetatable(L, -2); |
| 1009 | |
| 1010 | // lua stack: crep <arguments> "super" crep obj_ptr |
| 1011 | // or |
| 1012 | // lua stack: crep <arguments> obj_ptr |
| 1013 | |
| 1014 | if (has_bases) lua_pushvalue(L, -1); // obj_ptr |
| 1015 | lua_replace(L, 1); // obj_ptr |
| 1016 | |
| 1017 | // lua stack: obj_ptr <arguments> "super" crep obj_ptr |
| 1018 | // or |
| 1019 | // lua stack: obj_ptr <arguments> |
| 1020 | |
| 1021 | if (has_bases) |
| 1022 | { |
| 1023 | lua_pushcclosure(L, super_callback, 2); |
| 1024 | // lua stack: crep <arguments> "super" function |
| 1025 | lua_settable(L, LUA_GLOBALSINDEX); |
| 1026 | } |
| 1027 | |
| 1028 | // lua stack: crep <arguments> |
| 1029 |
nothing calls this directly
no test coverage detected