/* * Copyright (c) 2010-2011 OTClient * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "otclient.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void push_luavalue(const Outfit& outfit); bool luavalue_cast(int index, Outfit& outfit); void OTClient::registerLuaFunctions() { g_lua.bindGlobalFunction("exit", std::bind(&OTClient::exit, &g_client)); g_lua.bindGlobalFunction("setOnClose", std::bind(&OTClient::setOnClose, &g_client, _1)); g_lua.bindGlobalFunction("importDat", std::bind(&ThingsType::load, &g_thingsType, _1)); g_lua.bindGlobalFunction("importSpr", std::bind(&SpriteManager::load, &g_sprites, _1)); g_lua.bindGlobalFunction("getOufitColor", Outfit::getColor); g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &ProtocolLogin::create); g_lua.bindClassMemberFunction("login", &ProtocolLogin::login); g_lua.bindClassMemberFunction("cancelLogin", &ProtocolLogin::cancelLogin); g_lua.registerClass(); g_lua.registerClass(); g_lua.registerClass(); g_lua.registerClass(); g_lua.registerClass(); g_lua.registerClass(); g_lua.registerClass(); g_lua.registerClass(); g_lua.registerClass(); g_lua.bindClassStaticFunction("loginWorld", std::bind(&Game::loginWorld, &g_game, _1, _2, _3, _4, _5)); g_lua.bindClassStaticFunction("logout", std::bind(&Game::logout, &g_game, _1)); g_lua.bindClassStaticFunction("cancelLogin", std::bind(&Game::cancelLogin, &g_game)); g_lua.bindClassStaticFunction("isOnline", std::bind(&Game::isOnline, &g_game)); g_lua.bindClassStaticFunction("isOnline", std::bind(&Game::isOnline, &g_game)); g_lua.bindClassStaticFunction("openOutfitWindow", std::bind(&Game::openOutfitWindow, &g_game)); g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &UIItem::create); g_lua.bindClassMemberFunction("getItem", &UIItem::getItem); g_lua.bindClassMemberFunction("setItem", &UIItem::setItem); g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &UICreature::create); g_lua.bindClassMemberFunction("getCreature", &UICreature::getCreature); g_lua.bindClassMemberFunction("setCreature", &UICreature::setCreature); g_lua.bindClassMemberFunction("setOutfitType", &UICreature::setOutfitType); g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &UIWidget::create); #ifdef FORBIDDEN_FUNCTIONS g_lua.bindClassStaticFunction("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3)); g_lua.bindClassStaticFunction("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3)); #endif } void push_luavalue(const Outfit& outfit) { g_lua.newTable(); g_lua.pushInteger(outfit.getType()); g_lua.setField("type"); g_lua.pushInteger(outfit.getAddons()); g_lua.setField("addons"); g_lua.pushInteger(outfit.getHead()); g_lua.setField("head"); g_lua.pushInteger(outfit.getBody()); g_lua.setField("body"); g_lua.pushInteger(outfit.getLegs()); g_lua.setField("legs"); g_lua.pushInteger(outfit.getFeet()); g_lua.setField("feet"); } bool luavalue_cast(int index, Outfit& outfit) { if(g_lua.isTable(index)) { g_lua.getField("type", index); outfit.setType(g_lua.popInteger()); g_lua.getField("addons", index); outfit.setAddons(g_lua.popInteger()); g_lua.getField("head", index); outfit.setHead(g_lua.popInteger()); g_lua.getField("body", index); outfit.setBody(g_lua.popInteger()); g_lua.getField("legs", index); outfit.setLegs(g_lua.popInteger()); g_lua.getField("feet", index); outfit.setFeet(g_lua.popInteger()); return true; } return false; }