MCPcopy Create free account
hub / github.com/OGSR/OGSR-Engine / operator_dispatcher

Method operator_dispatcher

ogsr_engine/Luabind/src/class_rep.cpp:377–425  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

375
376
377int luabind::detail::class_rep::operator_dispatcher(lua_State* L)
378{
379 for (int i = 0; i < 2; ++i)
380 {
381 if (is_class_object(L, 1 + i))
382 {
383 int nargs = lua_gettop(L);
384
385 lua_pushvalue(L, lua_upvalueindex(1));
386 lua_gettable(L, 1 + i);
387
388 if (lua_isnil(L, -1))
389 {
390 lua_pop(L, 1);
391 continue;
392 }
393
394 lua_insert(L, 1); // move the function to the bottom
395
396 nargs = lua_toboolean(L, lua_upvalueindex(2)) ? 1 : nargs;
397
398 if (lua_toboolean(L, lua_upvalueindex(2))) // remove trailing nil
399 lua_remove(L, 3);
400
401 lua_call(L, nargs, 1);
402 return 1;
403 }
404 }
405
406 object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, 1));
407 class_rep* crep = obj->crep();
408
409 //Дефолтный __tostring
410 auto ptr = lua_tostring(L, lua_upvalueindex(1));
411 if (ptr && std::strcmp(ptr, "__tostring") == 0)
412 {
413 lua_pop(L, lua_gettop(L));
414 lua_pushstring(L, crep->name());
415 return 1;
416 }
417
418 lua_pop(L, lua_gettop(L));
419 string512 err_str;
420 xr_sprintf(err_str, "! No such operator [%s] defined in class [%s]", ptr, crep->name());
421 lua_pushstring(L, err_str);
422 lua_error(L);
423
424 return 0;
425}
426
427// this is called as metamethod __call on the class_rep.
428int luabind::detail::class_rep::constructor_dispatcher(lua_State* L)

Callers

nothing calls this directly

Calls 12

is_class_objectFunction · 0.85
lua_gettopFunction · 0.50
lua_pushvalueFunction · 0.50
lua_gettableFunction · 0.50
lua_insertFunction · 0.50
lua_tobooleanFunction · 0.50
lua_removeFunction · 0.50
lua_callFunction · 0.50
lua_touserdataFunction · 0.50
lua_pushstringFunction · 0.50
lua_errorFunction · 0.50
nameMethod · 0.45

Tested by

no test coverage detected