| 375 | |
| 376 | |
| 377 | int 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. |
| 428 | int luabind::detail::class_rep::constructor_dispatcher(lua_State* L) |
nothing calls this directly
no test coverage detected