LUABIND_API void add_overload( object const& context, char const* name, object const& fn) { function_object* f = *touserdata<function_object*>(getupvalue(fn, 1)); f->name = name; if (object overloads = context[name]) { if (is_luabind_function(overloads) && is_luabind_function(fn)) { f->next = *touserdata<function_object*>(getupvalue(overloads, 1)); f->keepalive = overloads; } } context[name] = fn; }
LUABIND_API void do_call_member_selection(lua_State* L, char const* name) { object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, -1)); lua_pushstring(L, name); lua_gettable(L, -2); lua_replace(L, -2); if (!is_luabind_function(L, -1)) return; // this (usually) means the function has not been // overridden by lua, call the default implementation lua_pop(L, 1); obj->crep()->get_default_table(L); // push the crep table lua_pushstring(L, name); lua_gettable(L, -2); lua_remove(L, -2); // remove the crep table }