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

Function dispatch_operator

Source/Misc/luabind/src/object_rep.cpp:177–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175 }
176
177 int dispatch_operator(lua_State* L)
178 {
179 int const name_upvalue = lua_upvalueindex(1);
180 for (int i = 0; i < 2; ++i)
181 {
182 if (get_instance(L, 1 + i))
183 {
184 int nargs = lua_gettop(L);
185
186 lua_pushvalue(L, name_upvalue); // operator name
187 // instance[operator name] (via get_instance_value / __index)
188 lua_gettable(L, 1 + i);
189
190 if (lua_isnil(L, -1))
191 {
192 lua_pop(L, 1);
193 continue;
194 }
195
196 lua_insert(L, 1); // move the function to the bottom
197
198 bool const is_unary = lua_toboolean(L, lua_upvalueindex(2)) ?
199 true : false; // Avoid MSVC "performance warning".
200
201 nargs = is_unary ? 1 : nargs;
202
203 if (is_unary) // remove trailing nil
204 lua_remove(L, 3);
205
206 lua_call(L, nargs, LUA_MULTRET);
207 return lua_gettop(L);
208 }
209 }
210
211 object_rep* inst = get_instance(L, 1);
212 assert(inst);
213 char const* op_name = lua_tostring(L, name_upvalue);
214
215 if (std::strcmp(op_name, "__eq") == 0)
216 {
217 object_rep* inst2 = get_instance(L, 2);
218 if (!inst2)
219 {
220 lua_pushboolean(L, false);
221 return 1;
222 }
223 class_id clsid = inst->crep()->classes().get(
224 inst->crep()->type());
225 void* addr = inst->get_instance(clsid).first;
226 void* addr2 = inst2->get_instance(clsid).first;
227 bool const null_inst = !addr;
228 if (!addr2)
229 {
230 clsid = inst2->crep()->classes().get(
231 inst2->crep()->type());
232 addr = inst->get_instance(clsid).first;
233 addr2 = inst2->get_instance(clsid).first;
234 if (!addr2)

Callers

nothing calls this directly

Calls 13

lua_gettopFunction · 0.85
lua_pushvalueFunction · 0.85
lua_gettableFunction · 0.85
lua_insertFunction · 0.85
lua_tobooleanFunction · 0.85
lua_removeFunction · 0.85
lua_callFunction · 0.85
lua_pushbooleanFunction · 0.85
get_class_nameFunction · 0.85
lua_pushfstringFunction · 0.85
lua_errorFunction · 0.85
get_instanceFunction · 0.70

Tested by

no test coverage detected