ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

lua.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/endian.h"
00024 #include "common/foreach.h"
00025 #include "common/system.h"
00026 #include "common/events.h"
00027 
00028 #include "math/matrix3.h"
00029 
00030 #include "engines/grim/debug.h"
00031 #include "engines/grim/lua.h"
00032 #include "engines/grim/actor.h"
00033 #include "engines/grim/costume.h"
00034 #include "engines/grim/registry.h"
00035 #include "engines/grim/localize.h"
00036 #include "engines/grim/grim.h"
00037 #include "engines/grim/savegame.h"
00038 #include "engines/grim/resource.h"
00039 #include "engines/grim/bitmap.h"
00040 #include "engines/grim/font.h"
00041 #include "engines/grim/set.h"
00042 #include "engines/grim/gfx_base.h"
00043 #include "engines/grim/model.h"
00044 #include "engines/grim/primitives.h"
00045 
00046 #include "engines/grim/lua/lauxlib.h"
00047 #include "engines/grim/lua/luadebug.h"
00048 #include "engines/grim/lua/lualib.h"
00049 
00050 namespace Grim {
00051 
00052 void LuaObjects::add(float number) {
00053     Obj obj;
00054     obj._type = Obj::Number;
00055     obj._value.number = number;
00056     _objects.push_back(obj);
00057 }
00058 
00059 void LuaObjects::add(int number) {
00060     Obj obj;
00061     obj._type = Obj::Number;
00062     obj._value.number = number;
00063     _objects.push_back(obj);
00064 }
00065 
00066 void LuaObjects::add(const PoolObjectBase *object) {
00067     Obj obj;
00068     obj._type = Obj::Object;
00069     obj._value.object = object;
00070     _objects.push_back(obj);
00071 }
00072 
00073 void LuaObjects::add(const char *str) {
00074     Obj obj;
00075     obj._type = Obj::String;
00076     obj._value.string = str;
00077     _objects.push_back(obj);
00078 }
00079 
00080 void LuaObjects::addNil() {
00081     Obj obj;
00082     obj._type = Obj::Nil;
00083     _objects.push_back(obj);
00084 }
00085 
00086 void LuaObjects::pushObjects() const {
00087     for (Common::List<Obj>::const_iterator i = _objects.begin(); i != _objects.end(); ++i) {
00088         const Obj &o = *i;
00089         switch (o._type) {
00090             case Obj::Nil:
00091                 lua_pushnil();
00092                 break;
00093             case Obj::Number:
00094                 lua_pushnumber(o._value.number);
00095                 break;
00096             case Obj::Object:
00097                 LuaBase::instance()->pushobject(o._value.object);
00098                 break;
00099             case Obj::String:
00100                 lua_pushstring(o._value.string);
00101                 break;
00102         }
00103     }
00104 }
00105 
00106 
00107 LuaBase *LuaBase::s_instance = nullptr;
00108 
00109 LuaBase::LuaBase() :
00110         _translationMode(0), _frameTimeCollection(0) {
00111     s_instance = this;
00112 
00113     lua_iolibopen();
00114     lua_strlibopen();
00115     lua_mathlibopen();
00116 }
00117 
00118 LuaBase::~LuaBase() {
00119     s_instance = nullptr;
00120 
00121     lua_removelibslists();
00122     lua_close();
00123     lua_iolibclose();
00124 }
00125 
00126 // Entries in the system table
00127 static struct {
00128     const char *name;
00129     int key;
00130 } system_defaults[] = {
00131     { "frameTime", 0 },
00132     { "movieTime", 0 }
00133 };
00134 
00135 void LuaBase::registerLua() {
00136     // Register system table
00137     lua_Object system_table = lua_createtable();
00138     lua_pushobject(system_table);
00139     lua_setglobal("system");
00140 
00141     lua_pushobject(system_table);
00142     refSystemTable = lua_ref(1);
00143 
00144     for (unsigned i = 0; i < ARRAYSIZE(system_defaults); i++) {
00145         lua_pushobject(lua_getref(refSystemTable));
00146         lua_pushstring(system_defaults[i].name);
00147         lua_pushnumber(system_defaults[i].key);
00148         lua_settable();
00149     }
00150 
00151     // Create and populate system.controls table
00152     lua_Object controls_table = lua_createtable();
00153     lua_pushobject(lua_getref(refSystemTable));
00154     lua_pushstring("controls");
00155     lua_pushobject(controls_table);
00156     lua_settable();
00157 
00158     for (int i = 0; controls[i].name; i++) {
00159         lua_pushobject(controls_table);
00160         lua_pushstring(controls[i].name);
00161         lua_pushnumber(controls[i].key);
00162         lua_settable();
00163     }
00164 
00165     lua_pushobject(lua_getref(refSystemTable));
00166     lua_pushstring("camChangeHandler");
00167     lua_pushcfunction(LUA_OPCODE(LuaBase, dummyHandler));
00168     lua_settable();
00169 
00170     lua_pushobject(lua_getref(refSystemTable));
00171     lua_pushstring("axisHandler");
00172     lua_pushcfunction(LUA_OPCODE(LuaBase, dummyHandler));
00173     lua_settable();
00174 
00175     lua_pushobject(lua_getref(refSystemTable));
00176     lua_pushstring("buttonHandler");
00177     lua_pushcfunction(LUA_OPCODE(LuaBase, dummyHandler));
00178     lua_settable();
00179 
00180     lua_pushobject(lua_getglobal("type"));
00181     refTypeOverride = lua_ref(true);
00182     lua_pushCclosure(LUA_OPCODE(LuaBase, typeOverride), 0);
00183     lua_setglobal("type");
00184 
00185     // Register constants for box types
00186     lua_pushnumber(Sector::NoneType);
00187     lua_setglobal("NONE");
00188     lua_pushnumber(Sector::WalkType);
00189     lua_setglobal("WALK");
00190     lua_pushnumber(Sector::CameraType);
00191     lua_setglobal("CAMERA");
00192     lua_pushnumber(Sector::SpecialType);
00193     lua_setglobal("SPECIAL");
00194     lua_pushnumber(Sector::HotType);
00195     lua_setglobal("HOT");
00196 
00197     lua_pushobject(lua_setfallback("concat", LUA_OPCODE(LuaBase, concatFallback)));
00198     refOldConcatFallback = lua_ref(1);
00199 
00200     // initialize Text globals
00201     lua_pushstring("x");
00202     refTextObjectX = lua_ref(true);
00203     lua_pushstring("y");
00204     refTextObjectY = lua_ref(true);
00205     lua_pushstring("font");
00206     refTextObjectFont = lua_ref(true);
00207     lua_pushstring("width");
00208     refTextObjectWidth = lua_ref(true);
00209     lua_pushstring("height");
00210     refTextObjectHeight = lua_ref(true);
00211     lua_pushstring("fgcolor");
00212     refTextObjectFGColor = lua_ref(true);
00213     lua_pushstring("bgcolor");
00214     refTextObjectBGColor = lua_ref(true);
00215     lua_pushstring("fxcolor");
00216     refTextObjectFXColor = lua_ref(true);
00217     lua_pushstring("hicolor");
00218     refTextObjectHIColor = lua_ref(true);
00219     lua_pushstring("duration");
00220     refTextObjectDuration = lua_ref(true);
00221     lua_pushstring("center");
00222     refTextObjectCenter = lua_ref(true);
00223     lua_pushstring("ljustify");
00224     refTextObjectLJustify = lua_ref(true);
00225     lua_pushstring("rjustify");
00226     refTextObjectRJustify = lua_ref(true);
00227     lua_pushstring("volume");
00228     refTextObjectVolume = lua_ref(true);
00229     lua_pushstring("pan");
00230     refTextObjectPan = lua_ref(true);
00231     lua_pushstring("background");
00232     refTextObjectBackground = lua_ref(true);
00233     lua_pushstring("layer");
00234     refTextObjectLayer = lua_ref(true);
00235 }
00236 
00237 void LuaBase::forceDemo() {
00238     lua_pushnumber(1);
00239     lua_setglobal("DEMO");
00240 }
00241 
00242 struct luaL_reg baseOpcodes[] = {
00243     { "  concatfallback", LUA_OPCODE(LuaBase, concatFallback) },
00244     { "  typeoverride", LUA_OPCODE(LuaBase, typeOverride) },
00245     { "  dfltcamera", LUA_OPCODE(LuaBase, dummyHandler) },
00246     { "  dfltcontrol", LUA_OPCODE(LuaBase, dummyHandler) },
00247 };
00248 
00249 void LuaBase::registerOpcodes() {
00250     luaL_openlib(baseOpcodes, ARRAYSIZE(baseOpcodes));
00251 }
00252 
00253 void LuaBase::loadSystemScript() {
00254     dofile("_system.lua");
00255 }
00256 
00257 void LuaBase::boot() {
00258     lua_pushnil();      // resumeSave
00259     lua_pushnil();      // bootParam - not used in scripts
00260     lua_call("BOOT");
00261 }
00262 
00263 void LuaBase::update(int frameTime, int movieTime) {
00264     _frameTimeCollection += frameTime;
00265     if (_frameTimeCollection > 10000) {
00266         _frameTimeCollection = 0;
00267         lua_collectgarbage(0);
00268     }
00269 
00270     lua_beginblock();
00271     setFrameTime(frameTime);
00272     lua_endblock();
00273 
00274     lua_beginblock();
00275     setMovieTime(movieTime);
00276     lua_endblock();
00277 
00278     // Run asynchronous tasks
00279     lua_runtasks();
00280 }
00281 
00282 void LuaBase::setFrameTime(float frameTime) {
00283     lua_pushobject(lua_getref(refSystemTable));
00284     lua_pushstring("frameTime");
00285     lua_pushnumber(frameTime);
00286     lua_settable();
00287 }
00288 
00289 void LuaBase::setMovieTime(float movieTime) {
00290     lua_pushobject(lua_getref(refSystemTable));
00291     lua_pushstring("movieTime");
00292     lua_pushnumber(movieTime);
00293     lua_settable();
00294 }
00295 
00296 int LuaBase::dofile(const char *filename) {
00297     Common::SeekableReadStream *stream;
00298     stream = g_resourceloader->openNewStreamFile(filename);
00299     if (!stream) {
00300         Debug::warning(Debug::Engine, "Cannot find script %s", filename);
00301         return 2;
00302     }
00303 
00304     int32 size = stream->size();
00305     char *buffer = new char[size];
00306     stream->read(buffer, size);
00307     int result = lua_dobuffer(const_cast<char *>(buffer), size, const_cast<char *>(filename));
00308     delete stream;
00309     delete[] buffer;
00310     return result;
00311 }
00312 
00313 bool LuaBase::callback(const char *name) {
00314     LuaObjects o;
00315     return callback(name, o);
00316 }
00317 
00318 bool LuaBase::callback(const char *name, const LuaObjects &objects) {
00319     lua_beginblock();
00320 
00321     lua_pushobject(lua_getref(refSystemTable));
00322     lua_pushstring(name);
00323     lua_Object table = lua_gettable();
00324 
00325     if (lua_istable(table)) {
00326         lua_pushobject(table);
00327         lua_pushstring(name);
00328         lua_Object func = lua_gettable();
00329         if (lua_isfunction(func)) {
00330             lua_pushobject(table);
00331             objects.pushObjects();
00332             lua_callfunction(func);
00333         } else {
00334             lua_endblock();
00335             return false;
00336         }
00337     } else if (lua_isfunction(table)) {
00338         objects.pushObjects();
00339         lua_callfunction(table);
00340     } else if (!lua_isnil(table)) {
00341         lua_endblock();
00342         return false;
00343     }
00344 
00345     lua_endblock();
00346     return true;
00347 }
00348 
00349 bool LuaBase::getbool(int num) {
00350     return !lua_isnil(lua_getparam(num));
00351 }
00352 
00353 void LuaBase::pushbool(bool val) {
00354     if (val)
00355         lua_pushnumber(1);
00356     else
00357         lua_pushnil();
00358 }
00359 
00360 void LuaBase::pushobject(const PoolObjectBase *o) {
00361     lua_pushusertag(o->getId(), o->getTag());
00362 }
00363 
00364 Actor *LuaBase::getactor(lua_Object obj) {
00365     return Actor::getPool().getObject(lua_getuserdata(obj));
00366 }
00367 
00368 Bitmap *LuaBase::getbitmap(lua_Object obj) {
00369     return Bitmap::getPool().getObject(lua_getuserdata(obj));
00370 }
00371 
00372 TextObject *LuaBase::gettextobject(lua_Object obj) {
00373     return TextObject::getPool().getObject(lua_getuserdata(obj));
00374 }
00375 
00376 Font *LuaBase::getfont(lua_Object obj) {
00377     return Font::getPool().getObject(lua_getuserdata(obj));
00378 }
00379 
00380 Color LuaBase::getcolor(lua_Object obj) {
00381     return Color(lua_getuserdata(obj));
00382 }
00383 
00384 PrimitiveObject *LuaBase::getprimitive(lua_Object obj) {
00385     return PrimitiveObject::getPool().getObject(lua_getuserdata(obj));
00386 }
00387 
00388 ObjectState *LuaBase::getobjectstate(lua_Object obj) {
00389     return ObjectState::getPool().getObject(lua_getuserdata(obj));
00390 }
00391 
00392 void LuaBase::dummyHandler() {
00393 }
00394 
00395 bool LuaBase::findCostume(lua_Object costumeObj, Actor *actor, Costume **costume) {
00396     *costume = nullptr;
00397     if (lua_isnil(costumeObj))
00398         return true;
00399     if (lua_isnumber(costumeObj)) {
00400         /*      int num = (int)lua_getnumber(costumeObj);*/
00401         error("findCostume: search by Id not implemented");
00402         // TODO get costume by ID ?
00403     }
00404     if (lua_isstring(costumeObj)) {
00405         *costume = actor->findCostume(lua_getstring(costumeObj));
00406         return *costume != nullptr;
00407     }
00408 
00409     return false;
00410 }
00411 
00412 Common::String LuaBase::parseMsgText(const char *msg, char *msgId) {
00413     Common::String translation = g_localizer->localize(msg);
00414     const char *secondSlash = nullptr;
00415 
00416     if (msg[0] == '/' && msgId) {
00417         secondSlash = strchr(msg + 1, '/');
00418         if (secondSlash) {
00419             strncpy(msgId, msg + 1, secondSlash - msg - 1);
00420             msgId[secondSlash - msg - 1] = 0;
00421         } else {
00422             msgId[0] = 0;
00423         }
00424     }
00425 
00426     if (_translationMode == 1)
00427         return secondSlash;
00428 
00429     if (_translationMode == 2)
00430         return msg;
00431 
00432     return translation;
00433 }
00434 
00435 void LuaBase::parseSayLineTable(lua_Object paramObj, bool *background, int *vol, int *pan, float *x, float *y) {
00436     lua_Object tableObj;
00437 
00438     lua_pushobject(paramObj);
00439     lua_pushobject(lua_getref(refTextObjectX));
00440     tableObj = lua_gettable();
00441     if (lua_isnumber(tableObj)) {
00442         if (x)
00443             *x = lua_getnumber(tableObj);
00444     }
00445 
00446     lua_pushobject(paramObj);
00447     lua_pushobject(lua_getref(refTextObjectY));
00448     tableObj = lua_gettable();
00449     if (lua_isnumber(tableObj)) {
00450         if (y)
00451             *y = lua_getnumber(tableObj);
00452     }
00453 
00454     lua_pushobject(paramObj);
00455     lua_pushobject(lua_getref(refTextObjectBackground));
00456     tableObj = lua_gettable();
00457     if (tableObj) {
00458         if (background)
00459             *background = (int)lua_getnumber(tableObj);
00460     }
00461 
00462     lua_pushobject(paramObj);
00463     lua_pushobject(lua_getref(refTextObjectVolume));
00464     tableObj = lua_gettable();
00465     if (lua_isnumber(tableObj)) {
00466         if (vol)
00467             *vol = (int)lua_getnumber(tableObj);
00468     }
00469 
00470     lua_pushobject(paramObj);
00471     lua_pushobject(lua_getref(refTextObjectPan));
00472     tableObj = lua_gettable();
00473     if (lua_isnumber(tableObj)) {
00474         if (pan)
00475             *pan = (int)lua_getnumber(tableObj);
00476     }
00477 }
00478 
00479 void LuaBase::setTextObjectParams(TextObjectCommon *textObject, lua_Object tableObj) {
00480     lua_Object keyObj;
00481 
00482     lua_pushobject(tableObj);
00483     lua_pushobject(lua_getref(refTextObjectX));
00484     keyObj = lua_gettable();
00485     if (keyObj) {
00486         if (lua_isnumber(keyObj)) {
00487             float num = lua_getnumber(keyObj);
00488             if (g_grim->getGameType() == GType_MONKEY4)
00489                 textObject->setX((int)(num * 320) + 320);
00490             else
00491                 textObject->setX((int)num);
00492         }
00493     }
00494 
00495     lua_pushobject(tableObj);
00496     lua_pushobject(lua_getref(refTextObjectY));
00497     keyObj = lua_gettable();
00498     if (keyObj) {
00499         if (lua_isnumber(keyObj)) {
00500             float num = lua_getnumber(keyObj);
00501             if (g_grim->getGameType() == GType_MONKEY4)
00502                 textObject->setY((int)(240 - (num * 240)));
00503             else
00504                 textObject->setY((int)num);
00505         }
00506     }
00507 
00508     lua_pushobject(tableObj);
00509     lua_pushobject(lua_getref(refTextObjectFont));
00510     keyObj = lua_gettable();
00511     if (keyObj) {
00512         if (g_grim->getGameType() == GType_MONKEY4 && lua_isstring(keyObj)) {
00513             const char *str = lua_getstring(keyObj);
00514             Font *font = nullptr;
00515             foreach (Font *f, Font::getPool()) {
00516                 if (f->getFilename() == str) {
00517                     font = f;
00518                 }
00519             }
00520             if (!font) {
00521                 font = g_resourceloader->loadFont(str);
00522             }
00523 
00524             textObject->setFont(font);
00525         } else if (lua_isuserdata(keyObj) && lua_tag(keyObj) == MKTAG('F','O','N','T')) {
00526             textObject->setFont(getfont(keyObj));
00527         } else if (g_grim->getGameType() == GType_MONKEY4 && !textObject->getFont() && g_grim->getGamePlatform() == Common::kPlatformPS2) {
00528             // HACK:
00529             warning("HACK: No default font set for PS2-version, just picking one for now");
00530             textObject->setFont(*Font::getPool().begin());
00531         }
00532     }
00533 
00534     lua_pushobject(tableObj);
00535     lua_pushobject(lua_getref(refTextObjectWidth));
00536     keyObj = lua_gettable();
00537     if (keyObj) {
00538         if (lua_isnumber(keyObj)) {
00539             textObject->setWidth((int)lua_getnumber(keyObj));
00540         }
00541     }
00542 
00543     lua_pushobject(tableObj);
00544     lua_pushobject(lua_getref(refTextObjectHeight));
00545     keyObj = lua_gettable();
00546     if (keyObj) {
00547         if (lua_isnumber(keyObj)) {
00548             textObject->setHeight((int)lua_getnumber(keyObj));
00549         }
00550     }
00551 
00552     lua_pushobject(tableObj);
00553     lua_pushobject(lua_getref(refTextObjectFGColor));
00554     keyObj = lua_gettable();
00555     if (keyObj) {
00556         if (lua_isuserdata(keyObj) && lua_tag(keyObj) == MKTAG('C','O','L','R')) {
00557             textObject->setFGColor(getcolor(keyObj));
00558         }
00559     }
00560 
00561     lua_pushobject(tableObj);
00562     lua_pushobject(lua_getref(refTextObjectBGColor));
00563     keyObj = lua_gettable();
00564     if (keyObj) {
00565         if (lua_isuserdata(keyObj) && lua_tag(keyObj) == MKTAG('C','O','L','R')) {
00566             //textObject->setBGColor(static_cast<Color *>(lua_getuserdata(keyObj)));
00567             warning("setTextObjectParams: dummy BGColor");
00568         }
00569     }
00570 
00571     lua_pushobject(tableObj);
00572     lua_pushobject(lua_getref(refTextObjectFXColor));
00573     keyObj = lua_gettable();
00574     if (keyObj) {
00575         if (lua_isuserdata(keyObj) && lua_tag(keyObj) == MKTAG('C','O','L','R')) {
00576             //textObject->setFXColor(static_cast<Color *>(lua_getuserdata(keyObj)));
00577             warning("setTextObjectParams: dummy FXColor");
00578         }
00579     }
00580 
00581     lua_pushobject(tableObj);
00582     lua_pushobject(lua_getref(refTextObjectCenter));
00583     keyObj = lua_gettable();
00584     if (keyObj) {
00585         if (!lua_isnil(keyObj)) {
00586             textObject->setJustify(1); //5
00587         }
00588     }
00589 
00590     lua_pushobject(tableObj);
00591     lua_pushobject(lua_getref(refTextObjectLJustify));
00592     keyObj = lua_gettable();
00593     if (keyObj) {
00594         if (!lua_isnil(keyObj)) {
00595             textObject->setJustify(2); //4
00596         }
00597     }
00598 
00599     lua_pushobject(tableObj);
00600     lua_pushobject(lua_getref(refTextObjectRJustify));
00601     keyObj = lua_gettable();
00602     if (keyObj) {
00603         if (!lua_isnil(keyObj)) {
00604             textObject->setJustify(3); //6
00605         }
00606     }
00607 
00608     lua_pushobject(tableObj);
00609     lua_pushobject(lua_getref(refTextObjectDuration));
00610     keyObj = lua_gettable();
00611     if (keyObj) {
00612         if (lua_isnumber(keyObj)) {
00613             textObject->setDuration((int)lua_getnumber(keyObj));
00614         }
00615     }
00616 
00617     // FIXME: remove check once the major save version is updated
00618     // currently it is needed for backward compatibility of old savegames
00619     if (lua_getref(refTextObjectLayer) == LUA_NOOBJECT)
00620         return;
00621     lua_pushobject(tableObj);
00622     lua_pushobject(lua_getref(refTextObjectLayer));
00623     keyObj = lua_gettable();
00624     if (keyObj) {
00625         if (lua_isnumber(keyObj)) {
00626             textObject->setLayer(lua_getnumber(keyObj));
00627         }
00628     }
00629 
00630 }
00631 
00632 void LuaBase::typeOverride() {
00633     lua_Object data = lua_getparam(1);
00634 
00635     if (lua_isuserdata(data)) {
00636         switch (lua_tag(data)) {
00637             case MKTAG('A','C','T','R'):
00638                 lua_pushstring("actor");
00639                 lua_pushnumber(lua_tag(data));
00640                 return;
00641             case MKTAG('C','O','S','T'):
00642                 lua_pushstring("costume");
00643                 lua_pushnumber(lua_tag(data));
00644                 return;
00645             case MKTAG('S','E','T',' '):
00646                 lua_pushstring("set");
00647                 lua_pushnumber(lua_tag(data));
00648                 return;
00649             case MKTAG('K','E','Y','F'):
00650                 lua_pushstring("keyframe");
00651                 lua_pushnumber(lua_tag(data));
00652                 return;
00653             default:
00654                 break;
00655         }
00656     }
00657 
00658     lua_pushobject(data);
00659     lua_callfunction(lua_getref(refTypeOverride));
00660     lua_Object param1 = lua_getresult(1);
00661     lua_Object param2 = lua_getresult(2);
00662     lua_pushobject(param1);
00663     lua_pushobject(param2);
00664 }
00665 
00666 void LuaBase::concatFallback() {
00667     lua_Object params[2];
00668     char result[200];
00669     char *strPtr;
00670 
00671     params[0] = lua_getparam(1);
00672     params[1] = lua_getparam(2);
00673     result[0] = 0;
00674 
00675     for (int i = 0; i < 2; i++) {
00676         if (!lua_isnil(params[i]) && !lua_isuserdata(params[i]) && !lua_isstring(params[i])) {
00677             lua_pushobject(params[0]);
00678             lua_pushobject(params[1]);
00679             lua_callfunction(lua_getref(refOldConcatFallback));
00680             lua_pushobject(lua_getresult(1));
00681             return;
00682         }
00683 
00684         int pos = strlen(result);
00685         strPtr = &result[pos];
00686 
00687         if (lua_isnil(params[i]))
00688             sprintf(strPtr, "(nil)");
00689         else if (lua_isstring(params[i]))
00690             sprintf(strPtr, "%s", lua_getstring(params[i]));
00691         else if (lua_tag(params[i]) == MKTAG('A','C','T','R')) {
00692             Actor *a = getactor(params[i]);
00693             sprintf(strPtr, "(actor%p:%s)", (void *)a,
00694                     (a->getCurrentCostume() && a->getCurrentCostume()->getModelNodes()) ?
00695                     a->getCurrentCostume()->getModelNodes()->_name : "");
00696         } else {
00697             lua_pushobject(params[0]);
00698             lua_pushobject(params[1]);
00699             lua_callfunction(lua_getref(refOldConcatFallback));
00700             lua_pushobject(lua_getresult(1));
00701             return;
00702         }
00703     }
00704 
00705     lua_pushstring(result);
00706 }
00707 
00708 }


Generated on Sat Dec 14 2019 05:00:38 for ResidualVM by doxygen 1.7.1
curved edge   curved edge