| 578 | |
| 579 | |
| 580 | int LuaHandle::ScriptSetCallIn(lua_State* L) { |
| 581 | const std::string ciName = luaL_checkstring(L, 1); |
| 582 | |
| 583 | const int ciCode = luaCallInDB.GetCode(ciName); |
| 584 | if (ciCode == 0) { |
| 585 | if (devMode) { |
| 586 | LuaLog(1, "Request to update an Unknown call-in (%s)\n", ciName.c_str()); |
| 587 | } |
| 588 | return luaL_pushnil(L); |
| 589 | } |
| 590 | |
| 591 | if (!L2H(L)->CanUseCallIn(ciName)) { |
| 592 | return luaL_pushnil(L); |
| 593 | } |
| 594 | |
| 595 | lua_settop(L, 2); |
| 596 | const bool haveFunc = lua_isfunction(L, 2); |
| 597 | |
| 598 | lua_checkstack(L, 4); |
| 599 | |
| 600 | lua_pushvalue(L, 2); // make a copy |
| 601 | lua_rawseti(L, LUA_CALLINSINDEX, ciCode); |
| 602 | |
| 603 | lua_pushstring(L, ciName.c_str()); |
| 604 | lua_pushvalue(L, 2); // make a copy |
| 605 | lua_rawset(L, LUA_CALLINSINDEX); |
| 606 | |
| 607 | const std::string& eventName = luaCallInDB.GetEventName(ciName); |
| 608 | if (eventHandler.IsManaged(eventName)) { |
| 609 | lua_pushboolean(L, L2H(L)->UpdateCallIn(ciName, haveFunc)); |
| 610 | } |
| 611 | else { |
| 612 | lua_pushboolean(L, true); |
| 613 | } |
| 614 | |
| 615 | return 1; |
| 616 | } |
| 617 | |
| 618 | |
| 619 | //============================================================================// |
nothing calls this directly
no test coverage detected