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

lua_v1.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/savefile.h"
00025 #include "common/system.h"
00026 #include "common/config-manager.h"
00027 
00028 #include "graphics/pixelbuffer.h"
00029 #include "graphics/renderer.h"
00030 #include "graphics/colormasks.h"
00031 
00032 #include "math/matrix3.h"
00033 
00034 #include "engines/grim/debug.h"
00035 #include "engines/grim/lua_v1.h"
00036 #include "engines/grim/registry.h"
00037 #include "engines/grim/grim.h"
00038 #include "engines/grim/savegame.h"
00039 #include "engines/grim/resource.h"
00040 #include "engines/grim/bitmap.h"
00041 #include "engines/grim/font.h"
00042 #include "engines/grim/gfx_base.h"
00043 #include "engines/grim/localize.h"
00044 
00045 #include "engines/grim/lua/lauxlib.h"
00046 #include "engines/grim/lua/luadebug.h"
00047 
00048 namespace Grim {
00049 
00050 byte clamp_color(int c) {
00051     if (c < 0)
00052         return 0;
00053     else if (c > 255)
00054         return 255;
00055     else
00056         return c;
00057 }
00058 
00059 int luaA_passresults();
00060 
00061 void Lua_V1::new_dofile() {
00062     const char *fname_str = luaL_check_string(1);
00063     if (dofile(fname_str) == 0)
00064         if (luaA_passresults() == 0)
00065             lua_pushuserdata(0);
00066 }
00067 
00068 // Debugging message functions
00069 
00070 void Lua_V1::PrintDebug() {
00071     if (Debug::isChannelEnabled(Debug::Scripts | Debug::Info)) {
00072         Common::String msg("Debug: ");
00073         lua_Object strObj = lua_getparam(1);
00074         if (lua_isnil(strObj))
00075             msg += "(nil)";
00076         if (!lua_isstring(strObj))
00077             return;
00078         msg += Common::String(lua_getstring(strObj));
00079         debugN("%s", msg.c_str());
00080     }
00081 }
00082 
00083 void Lua_V1::PrintError() {
00084     if (Debug::isChannelEnabled(Debug::Scripts | Debug::Error)) {
00085         Common::String msg("Error: ");
00086         lua_Object strObj = lua_getparam(1);
00087         if (lua_isnil(strObj))
00088             msg += "(nil)";
00089         if (!lua_isstring(strObj))
00090             return;
00091         msg += Common::String(lua_getstring(strObj));
00092         debugN("%s", msg.c_str());
00093     }
00094 }
00095 
00096 void Lua_V1::PrintWarning() {
00097     if (Debug::isChannelEnabled(Debug::Scripts | Debug::Warning)) {
00098         Common::String msg("Warning: ");
00099         lua_Object strObj = lua_getparam(1);
00100         if (lua_isnil(strObj))
00101             msg += "(nil)";
00102         if (!lua_isstring(strObj))
00103             return;
00104         msg += Common::String(lua_getstring(strObj));
00105         debugN("%s", msg.c_str());
00106     }
00107 }
00108 
00109 void Lua_V1::FunctionName() {
00110     const char *name;
00111     char buf[256];
00112     const char *filename = nullptr;
00113     int32 line;
00114     lua_Object param1 = lua_getparam(1);
00115 
00116     if (!lua_isfunction(param1)) {
00117         sprintf(buf, "function InvalidArgsToFunctionName");
00118         lua_pushstring(buf);
00119         return;
00120     }
00121 
00122     lua_funcinfo(param1, &filename, &line);
00123     switch (*lua_getobjname(param1, &name)) {
00124     case 'g':
00125         sprintf(buf, "function %.100s", name);
00126         break;
00127     case 't':
00128         sprintf(buf, "`%.100s' tag method", name);
00129         break;
00130     default:
00131         {
00132             if (line == 0)
00133                 sprintf(buf, "main of %.100s", filename);
00134             else if (line < 0)
00135                 sprintf(buf, "%.100s", filename);
00136             else {
00137                 sprintf(buf, "function (%.100s:%d)", filename, (int)line);
00138                 filename = nullptr;
00139             }
00140         }
00141     }
00142     int curr_line = lua_currentline(param1);
00143     if (curr_line > 0)
00144         sprintf(buf + strlen(buf), " at line %d", curr_line);
00145     if (filename)
00146         sprintf(buf + strlen(buf), " [in file %.100s]", filename);
00147     lua_pushstring(buf);
00148 }
00149 
00150 void Lua_V1::CheckForFile() {
00151     lua_Object strObj = lua_getparam(1);
00152 
00153     if (!lua_isstring(strObj))
00154         return;
00155 
00156     const char *filename = lua_getstring(strObj);
00157     pushbool(SearchMan.hasFile(filename));
00158 }
00159 
00160 void Lua_V1::MakeColor() {
00161     lua_Object rObj = lua_getparam(1);
00162     lua_Object gObj = lua_getparam(2);
00163     lua_Object bObj = lua_getparam(3);
00164     int r, g, b;
00165 
00166     if (!lua_isnumber(rObj))
00167         r = 0;
00168     else
00169         r = clamp_color((int)lua_getnumber(rObj));
00170 
00171     if (!lua_isnumber(gObj))
00172         g = 0;
00173     else
00174         g = clamp_color((int)lua_getnumber(gObj));
00175 
00176     if (!lua_isnumber(bObj))
00177         b = 0;
00178     else
00179         b = clamp_color((int)lua_getnumber(bObj));
00180 
00181     Color c(r, g, b);
00182     int32 cTag = c.toEncodedValue();
00183     if (g_grim->getGameType() == GType_MONKEY4)
00184         cTag |= (0xFF << 24);
00185     lua_pushusertag(cTag, MKTAG('C','O','L','R'));
00186 }
00187 
00188 void Lua_V1::GetColorComponents() {
00189     lua_Object colorObj = lua_getparam(1);
00190     Color c(getcolor(colorObj));
00191     lua_pushnumber(c.getRed());
00192     lua_pushnumber(c.getGreen());
00193     lua_pushnumber(c.getBlue());
00194 }
00195 
00196 void Lua_V1::ReadRegistryValue() {
00197     lua_Object keyObj = lua_getparam(1);
00198 
00199     if (!lua_isstring(keyObj)) {
00200         lua_pushnil();
00201         return;
00202     }
00203     const char *key = lua_getstring(keyObj);
00204 
00205     Registry::ValueType type = g_registry->getValueType(key);
00206     switch (type) {
00207     case Registry::String:
00208         lua_pushstring(g_registry->getString(key).c_str());
00209         break;
00210     case Registry::Integer:
00211         lua_pushnumber(g_registry->getInt(key));
00212         break;
00213     case Registry::Boolean:
00214         pushbool(g_registry->getBool(key));
00215         break;
00216     }
00217 }
00218 
00219 void Lua_V1::WriteRegistryValue() {
00220     lua_Object keyObj = lua_getparam(1);
00221     lua_Object valObj = lua_getparam(2);
00222 
00223     if (!lua_isstring(keyObj))
00224         return;
00225 
00226     const char *key = lua_getstring(keyObj);
00227     if (strcmp(key, "GrimMannyState") == 0) //This isn't used. it's probably a left over from testing phase.
00228         return;
00229 
00230     // Check isnumber first, because isstring returns true for numbers
00231     if (lua_isnumber(valObj)) {
00232         int val = (int)lua_getnumber(valObj);
00233         g_registry->setInt(key, val);
00234     } else if (lua_isstring(valObj)) {
00235         const char *val = lua_getstring(valObj);
00236         g_registry->setString(key, val);
00237     }
00238 }
00239 
00240 void Lua_V1::GetAngleBetweenVectors() {
00241     lua_Object vec1Obj = lua_getparam(1);
00242     lua_Object vec2Obj = lua_getparam(2);
00243 
00244     if (!lua_istable(vec1Obj) || !lua_istable(vec2Obj)) {
00245         lua_pushnil();
00246         return;
00247     }
00248 
00249     lua_pushobject(vec1Obj);
00250     lua_pushstring("x");
00251     lua_Object table = lua_gettable();
00252     float x1 = lua_getnumber(table);
00253     lua_pushobject(vec1Obj);
00254     lua_pushstring("y");
00255     table = lua_gettable();
00256     float y1 = lua_getnumber(table);
00257     lua_pushobject(vec1Obj);
00258     lua_pushstring("z");
00259     table = lua_gettable();
00260     float z1 = lua_getnumber(table);
00261     lua_pushobject(vec2Obj);
00262     lua_pushstring("x");
00263     table = lua_gettable();
00264     float x2 = lua_getnumber(table);
00265     lua_pushobject(vec2Obj);
00266     lua_pushstring("y");
00267     table = lua_gettable();
00268     float y2 = lua_getnumber(table);
00269     lua_pushobject(vec2Obj);
00270     lua_pushstring("z");
00271     table = lua_gettable();
00272     float z2 = lua_getnumber(table);
00273 
00274     Math::Vector3d vec1(x1, y1, z1);
00275     Math::Vector3d vec2(x2, y2, z2);
00276     vec1.normalize();
00277     vec2.normalize();
00278 
00279     float dot = vec1.dotProduct(vec2);
00280     float angle = 90.0f - (180.0f * asin(dot)) / LOCAL_PI;
00281     if (angle < 0)
00282         angle = -angle;
00283     lua_pushnumber(angle);
00284 }
00285 
00286 void Lua_V1::Is3DHardwareEnabled() {
00287     pushbool(g_driver->isHardwareAccelerated());
00288 }
00289 
00290 void Lua_V1::SetHardwareState() {
00291     // changing only in config setup (software/hardware rendering)
00292     bool accel = getbool(1);
00293 
00294     Graphics::RendererType renderer = accel ? Graphics::kRendererTypeOpenGL : Graphics::kRendererTypeTinyGL;
00295     renderer = Graphics::getBestMatchingAvailableRendererType(renderer);
00296     ConfMan.set("renderer", Graphics::getRendererTypeCode(renderer));
00297 
00298     g_grim->changeHardwareState();
00299 }
00300 
00301 void Lua_V1::SetVideoDevices() {
00302     /*int devId = (int)*/lua_getnumber(lua_getparam(1));
00303     /*int modeId = (int)*/lua_getnumber(lua_getparam(2));
00304     // ignore setting video devices
00305 }
00306 
00307 void Lua_V1::GetVideoDevices() {
00308     lua_pushnumber(0.0);
00309     lua_pushnumber(-1.0);
00310 }
00311 
00312 void Lua_V1::EnumerateVideoDevices() {
00313     lua_Object result = lua_createtable();
00314     lua_pushobject(result);
00315     lua_pushnumber(0.0); // id of device
00316     lua_pushstring(g_driver->getVideoDeviceName()); // name of device
00317     lua_settable();
00318     lua_pushobject(result);
00319 }
00320 
00321 void Lua_V1::Enumerate3DDevices() {
00322     lua_Object result = lua_createtable();
00323     lua_Object numObj = lua_getparam(1);
00324     if (!lua_isnumber(numObj))
00325         return;
00326 /*  int num = (int)lua_getnumber(numObj);*/
00327     lua_pushobject(result);
00328     lua_pushnumber(-1.0);
00329     if (g_driver->isHardwareAccelerated()) {
00330         lua_pushstring("OpenGL"); // type of 3d renderer
00331     } else {
00332         lua_pushstring("/engn003/Software"); // type of 3d renderer
00333     }
00334     lua_settable();
00335     lua_pushobject(result);
00336 }
00337 
00338 /* RotateVector takes a vector and rotates it around
00339  * the point (0,0,0) by the requested number of degrees.
00340  * This function is used to calculate the locations for
00341  * getting on and off of the Bone Wagon and for going up
00342  * and down the slide with the chain at the end of the world.
00343  */
00344 void Lua_V1::RotateVector() {
00345     lua_Object vecObj = lua_getparam(1);
00346     lua_Object rotObj = lua_getparam(2);
00347 
00348     if (!lua_istable(vecObj) || !lua_istable(rotObj)) {
00349         lua_pushnil();
00350         return;
00351     }
00352 
00353     lua_pushobject(vecObj);
00354     lua_pushstring("x");
00355     float x = lua_getnumber(lua_gettable());
00356     lua_pushobject(vecObj);
00357     lua_pushstring("y");
00358     float y = lua_getnumber(lua_gettable());
00359     lua_pushobject(vecObj);
00360     lua_pushstring("z");
00361     float z = lua_getnumber(lua_gettable());
00362     Math::Vector3d vec(x, y, z);
00363 
00364     lua_pushobject(rotObj);
00365     lua_pushstring("x");
00366     Math::Angle pitch = lua_getnumber(lua_gettable());
00367     lua_pushobject(rotObj);
00368     lua_pushstring("y");
00369     Math::Angle yaw = lua_getnumber(lua_gettable());
00370     lua_pushobject(rotObj);
00371     lua_pushstring("z");
00372     Math::Angle roll = lua_getnumber(lua_gettable());
00373 
00374     Math::Matrix3 mat;
00375     mat.buildFromEuler(yaw, pitch, roll, Math::EO_ZXY);
00376     mat.transformVector(&vec);
00377 
00378     lua_Object resObj = lua_createtable();
00379     lua_pushobject(resObj);
00380     lua_pushstring("x");
00381     lua_pushnumber(vec.x());
00382     lua_settable();
00383     lua_pushobject(resObj);
00384     lua_pushstring("y");
00385     lua_pushnumber(vec.y());
00386     lua_settable();
00387     lua_pushobject(resObj);
00388     lua_pushstring("z");
00389     lua_pushnumber(vec.z());
00390     lua_settable();
00391 
00392     lua_pushobject(resObj);
00393 }
00394 
00395 void Lua_V1::FileFindDispose() {
00396     g_grim->_listFiles.clear();
00397     g_grim->_listFilesIter = nullptr;
00398 }
00399 
00400 void Lua_V1::FileFindNext() {
00401     if (g_grim->_listFilesIter == g_grim->_listFiles.end()) {
00402         lua_pushnil();
00403         Lua_V1::FileFindDispose();
00404     } else {
00405         lua_pushstring(g_grim->_listFilesIter->c_str());
00406         g_grim->_listFilesIter++;
00407     }
00408 }
00409 
00410 void Lua_V1::FileFindFirst() {
00411     lua_Object extObj = lua_getparam(1);
00412     if (!lua_isstring(extObj)) {
00413         lua_pushnil();
00414         return;
00415     }
00416 
00417     Lua_V1::FileFindDispose();
00418 
00419     const char *extension = lua_getstring(extObj);
00420     Common::String searchString = extension;
00421     if (searchString == "*.gsv") {
00422         searchString = "grim##.gsv";
00423     }
00424     Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
00425     g_grim->_listFiles = saveFileMan->listSavefiles(searchString);
00426     Common::sort(g_grim->_listFiles.begin(), g_grim->_listFiles.end());
00427     g_grim->_listFilesIter = g_grim->_listFiles.begin();
00428 
00429     if (g_grim->_listFilesIter == g_grim->_listFiles.end())
00430         lua_pushnil();
00431     else
00432         Lua_V1::FileFindNext();
00433 }
00434 
00435 void Lua_V1::PerSecond() {
00436     lua_Object rateObj = lua_getparam(1);
00437 
00438     if (!lua_isnumber(rateObj)) {
00439         lua_pushnil();
00440         return;
00441     }
00442     float rate = lua_getnumber(rateObj);
00443     lua_pushnumber(g_grim->getPerSecond(rate));
00444 }
00445 
00446 void Lua_V1::EnableControl() {
00447     lua_Object numObj = lua_getparam(1);
00448 
00449     if (!lua_isnumber(numObj)) {
00450         lua_pushnil();
00451         return;
00452     }
00453     int num = (int)lua_getnumber(numObj);
00454     if (num < 0 || num >= KEYCODE_EXTRA_LAST)
00455         error("control identifier out of range");
00456 
00457     g_grim->enableControl(num);
00458 }
00459 
00460 void Lua_V1::DisableControl() {
00461     lua_Object numObj = lua_getparam(1);
00462 
00463     if (!lua_isnumber(numObj)) {
00464         lua_pushnil();
00465         return;
00466     }
00467     int num = (int)lua_getnumber(numObj);
00468     if (num < 0 || num >= KEYCODE_EXTRA_LAST)
00469         error("control identifier out of range");
00470 
00471     g_grim->disableControl(num);
00472 }
00473 
00474 void Lua_V1::GetControlState() {
00475     lua_Object numObj = lua_getparam(1);
00476 
00477     if (!lua_isnumber(numObj))
00478         return;
00479 
00480     int num = (int)lua_getnumber(numObj);
00481     if (num < 0 || num >= KEYCODE_EXTRA_LAST)
00482         error("control identifier out of range");
00483     if (num >= KEYCODE_AXIS_JOY1_X && num <= KEYCODE_AXIS_MOUSE_Z)
00484         lua_pushnumber(g_grim->getControlAxis(num));
00485     else {
00486         pushbool(g_grim->getControlState(num)); // key down, originaly it push number if key down
00487         //pushnil or number, what is is ?
00488     }
00489 }
00490 
00491 void Lua_V1::Exit() {
00492     g_grim->quitGame();
00493 }
00494 
00495 void Lua_V1::SetSpeechMode() {
00496     GrimEngine::SpeechMode mode = (GrimEngine::SpeechMode)((int)lua_getnumber(lua_getparam(1)));
00497     if (mode >= 1 && mode <= 3)
00498         g_grim->setSpeechMode(mode);
00499 }
00500 
00501 void Lua_V1::GetSpeechMode() {
00502     lua_pushnumber(g_grim->getSpeechMode());
00503 }
00504 
00505 void Lua_V1::GetDiskFreeSpace() {
00506     //the ps2 version of emi wants more than 600 KB
00507     //grim: amount of free space in MB, used for creating saves
00508     lua_pushnumber(700);
00509 }
00510 
00511 void Lua_V1::GetCurrentScript() {
00512     current_script();
00513 }
00514 
00515 void Lua_V1::GetSaveGameImage() {
00516     int width = 250, height = 188;
00517     Bitmap *screenshot;
00518     int dataSize;
00519 
00520     lua_Object param = lua_getparam(1);
00521     if (!lua_isstring(param)) {
00522         lua_pushnil();
00523         return;
00524     }
00525     const char *filename = lua_getstring(param);
00526     SaveGame *savedState = SaveGame::openForLoading(filename);
00527     if (!savedState || !savedState->isCompatible()) {
00528         delete savedState;
00529         lua_pushnil();
00530         return;
00531     }
00532     dataSize = savedState->beginSection('SIMG');
00533     uint16 *data = new uint16[dataSize / 2];
00534     for (int l = 0; l < dataSize / 2; l++) {
00535         data[l] = savedState->readLEUint16();
00536     }
00537     Graphics::PixelBuffer buf(Graphics::createPixelFormat<565>(), (byte *)data);
00538     screenshot = new Bitmap(buf, width, height, "screenshot");
00539     delete[] data;
00540     if (screenshot) {
00541         lua_pushusertag(screenshot->getId(), MKTAG('V','B','U','F'));
00542     } else {
00543         lua_pushnil();
00544         warning("Could not restore screenshot from file");
00545         delete savedState;
00546         return;
00547     }
00548     savedState->endSection();
00549     delete savedState;
00550 }
00551 
00552 void Lua_V1::SubmitSaveGameData() {
00553     lua_Object table, table2;
00554     SaveGame *savedState;
00555     const char *str;
00556     table = lua_getparam(1);
00557 
00558     savedState = g_grim->savedState();
00559     if (!savedState)
00560         error("Cannot obtain saved game");
00561     savedState->beginSection('SUBS');
00562     int count = 0;
00563     Common::String localized;
00564     for (;;) {
00565         lua_pushobject(table);
00566         lua_pushnumber(count);
00567         count++;
00568         table2 = lua_gettable();
00569         if (lua_isnil(table2))
00570             break;
00571         str = lua_getstring(table2);
00572         if (g_grim->getGameType() == GType_MONKEY4 &&
00573             g_grim->getGamePlatform() == Common::kPlatformPS2) {
00574             if (count == 1) {
00575                 localized = g_localizer->localize(str);
00576             }
00577         }
00578         int32 len = strlen(str) + 1;
00579         savedState->writeLESint32(len);
00580         savedState->write(str, len);
00581     }
00582     savedState->endSection();
00583     
00584     //give ps2 saves a human-readable name
00585     if (g_grim->getGameType() == GType_MONKEY4 &&
00586         g_grim->getGamePlatform() == Common::kPlatformPS2) {
00587         savedState->beginSection('PS2S');
00588         savedState->writeLESint32(localized.size() + 1);
00589         savedState->write(localized.c_str(), localized.size() + 1);
00590         savedState->endSection();
00591     }
00592 }
00593 
00594 void Lua_V1::GetSaveGameData() {
00595     lua_Object param = lua_getparam(1);
00596     if (!lua_isstring(param))
00597         return;
00598     Common::String filename(lua_getstring(param));
00599     if (g_grim->getGameType() == GType_MONKEY4 &&
00600         g_grim->getGamePlatform() == Common::kPlatformPS2) {
00601         filename += ".ps2";
00602     }
00603     SaveGame *savedState = SaveGame::openForLoading(filename);
00604     lua_Object result = lua_createtable();
00605 
00606     if (!savedState || !savedState->isCompatible()) {
00607         lua_pushobject(result);
00608         lua_pushnumber(2);
00609         lua_pushstring("mo.set"); // Just a placeholder to not make it throw a lua error
00610         lua_settable();
00611         lua_pushobject(result);
00612 
00613         if (!savedState) {
00614             warning("Savegame %s is invalid", filename.c_str());
00615         } else {
00616             warning("Savegame %s is incompatible with this ResidualVM build. Save version: %d.%d; current version: %d.%d",
00617                     filename.c_str(), savedState->saveMajorVersion(), savedState->saveMinorVersion(),
00618                     SaveGame::SAVEGAME_MAJOR_VERSION, SaveGame::SAVEGAME_MINOR_VERSION);
00619         }
00620         delete savedState;
00621         return;
00622     }
00623     int32 dataSize = savedState->beginSection('SUBS');
00624 
00625     char str[200];
00626     int32 strSize;
00627     int count = 0;
00628 
00629     for (;;) {
00630         if (dataSize <= 0)
00631             break;
00632         strSize = savedState->readLESint32();
00633         savedState->read(str, strSize);
00634         lua_pushobject(result);
00635         lua_pushnumber(count);
00636         lua_pushstring(str);
00637         lua_settable();
00638         dataSize -= strSize;
00639         dataSize -= 4;
00640         count++;
00641     }
00642     lua_pushobject(result);
00643 
00644     savedState->endSection();
00645     delete savedState;
00646 }
00647 
00648 void Lua_V1::Load() {
00649     lua_Object fileNameObj = lua_getparam(1);
00650     if (lua_isnil(fileNameObj)) {
00651         g_grim->loadGame("");
00652     } else if (lua_isstring(fileNameObj)) {
00653         Common::String fileName(lua_getstring(fileNameObj));
00654         if (g_grim->getGameType() == GType_MONKEY4 &&
00655             g_grim->getGamePlatform() == Common::kPlatformPS2) {
00656             fileName += ".ps2";
00657         }
00658         g_grim->loadGame(fileName);
00659     } else {
00660         warning("Load() fileName is wrong");
00661         return;
00662     }
00663 }
00664 
00665 void Lua_V1::Save() {
00666     lua_Object fileNameObj = lua_getparam(1);
00667     if (lua_isnil(fileNameObj)) {
00668         g_grim->saveGame("");
00669     } else if (lua_isstring(fileNameObj)) {
00670         Common::String fileName(lua_getstring(fileNameObj));
00671         if (g_grim->getGameType() == GType_MONKEY4 &&
00672             g_grim->getGamePlatform() == Common::kPlatformPS2) {
00673             fileName += ".ps2";
00674         }
00675         g_grim->saveGame(fileName);
00676     } else {
00677         warning("Save() fileName is wrong");
00678         return;
00679     }
00680 }
00681 
00682 void Lua_V1::Remove() {
00683     if (g_system->getSavefileManager()->removeSavefile(luaL_check_string(1)))
00684         lua_pushuserdata(0);
00685     else {
00686         lua_pushnil();
00687         lua_pushstring(g_system->getSavefileManager()->getErrorDesc().c_str());
00688     }
00689 }
00690 
00691 void Lua_V1::LockFont() {
00692     lua_Object param1 = lua_getparam(1);
00693     if (lua_isstring(param1)) {
00694         const char *fontName = lua_getstring(param1);
00695         Font *result = g_resourceloader->loadFont(fontName);
00696         if (result) {
00697             lua_pushusertag(result->getId(), MKTAG('F','O','N','T'));
00698             return;
00699         }
00700     }
00701 
00702     lua_pushnil();
00703 }
00704 
00705 void Lua_V1::EnableDebugKeys() {
00706 }
00707 
00708 void Lua_V1::LightMgrSetChange() {
00709     // that seems only used when some control panel is opened
00710 }
00711 
00712 void Lua_V1::LightMgrStartup() {
00713     // we will not implement this opcode
00714 }
00715 
00716 void Lua_V1::JustLoaded() {
00717     Debug::error("OPCODE USAGE VERIFICATION: JustLoaded");
00718 }
00719 
00720 void Lua_V1::SetEmergencyFont() {
00721     Debug::error("OPCODE USAGE VERIFICATION: SetEmergencyFont");
00722 }
00723 
00724 
00725 // Stub function for builtin functions not yet implemented
00726 static void stubWarning(const char *funcName) {
00727     warning("Stub function: %s", funcName);
00728 }
00729 
00730 #define STUB_FUNC(name) void name() { stubWarning(#name); }
00731 
00732 STUB_FUNC(Lua_V1::SetActorInvClipNode)
00733 STUB_FUNC(Lua_V1::NukeResources)
00734 STUB_FUNC(Lua_V1::ResetTextures)
00735 STUB_FUNC(Lua_V1::AttachToResources)
00736 STUB_FUNC(Lua_V1::DetachFromResources)
00737 STUB_FUNC(Lua_V1::SetActorClipPlane)
00738 STUB_FUNC(Lua_V1::SetActorClipActive)
00739 STUB_FUNC(Lua_V1::FlushControls)
00740 STUB_FUNC(Lua_V1::GetCameraLookVector)
00741 STUB_FUNC(Lua_V1::SetCameraRoll)
00742 STUB_FUNC(Lua_V1::SetCameraInterest)
00743 STUB_FUNC(Lua_V1::GetCameraPosition)
00744 STUB_FUNC(Lua_V1::SpewStartup)
00745 STUB_FUNC(Lua_V1::WorldToScreen)
00746 STUB_FUNC(Lua_V1::SetActorRoll)
00747 STUB_FUNC(Lua_V1::SetActorFrustrumCull)
00748 STUB_FUNC(Lua_V1::DriveActorTo)
00749 STUB_FUNC(Lua_V1::GetTranslationMode)
00750 STUB_FUNC(Lua_V1::SetTranslationMode)
00751 STUB_FUNC(Lua_V1::WalkActorToAvoiding)
00752 STUB_FUNC(Lua_V1::GetActorChores)
00753 STUB_FUNC(Lua_V1::SetCameraPosition)
00754 STUB_FUNC(Lua_V1::GetCameraFOV)
00755 STUB_FUNC(Lua_V1::SetCameraFOV)
00756 STUB_FUNC(Lua_V1::GetCameraRoll)
00757 STUB_FUNC(Lua_V1::GetMemoryUsage)
00758 STUB_FUNC(Lua_V1::GetFontDimensions)
00759 STUB_FUNC(Lua_V1::PurgeText)
00760 
00761 struct luaL_reg grimMainOpcodes[] = {
00762     { "EngineDisplay", LUA_OPCODE(Lua_V1, EngineDisplay) },
00763     { "CheckForFile", LUA_OPCODE(Lua_V1, CheckForFile) },
00764     { "Load", LUA_OPCODE(Lua_V1, Load) },
00765     { "Save", LUA_OPCODE(Lua_V1, Save) },
00766     { "remove", LUA_OPCODE(Lua_V1, Remove) },
00767     { "SetActorColormap", LUA_OPCODE(Lua_V1, SetActorColormap) },
00768     { "GetActorCostume", LUA_OPCODE(Lua_V1, GetActorCostume) },
00769     { "SetActorCostume", LUA_OPCODE(Lua_V1, SetActorCostume) },
00770     { "SetActorScale", LUA_OPCODE(Lua_V1, SetActorScale) },
00771     { "GetActorTimeScale", LUA_OPCODE(Lua_V1, GetActorTimeScale) },
00772     { "SetActorTimeScale", LUA_OPCODE(Lua_V1, SetActorTimeScale) },
00773     { "GetActorNodeLocation", LUA_OPCODE(Lua_V1, GetActorNodeLocation) },
00774     { "SetActorWalkChore", LUA_OPCODE(Lua_V1, SetActorWalkChore) },
00775     { "SetActorTurnChores", LUA_OPCODE(Lua_V1, SetActorTurnChores) },
00776     { "SetActorRestChore", LUA_OPCODE(Lua_V1, SetActorRestChore) },
00777     { "SetActorMumblechore", LUA_OPCODE(Lua_V1, SetActorMumblechore) },
00778     { "SetActorTalkChore", LUA_OPCODE(Lua_V1, SetActorTalkChore) },
00779     { "SetActorWalkRate", LUA_OPCODE(Lua_V1, SetActorWalkRate) },
00780     { "GetActorWalkRate", LUA_OPCODE(Lua_V1, GetActorWalkRate) },
00781     { "SetActorTurnRate", LUA_OPCODE(Lua_V1, SetActorTurnRate) },
00782     { "SetSelectedActor", LUA_OPCODE(Lua_V1, SetSelectedActor) },
00783     { "LoadActor", LUA_OPCODE(Lua_V1, LoadActor) },
00784     { "GetActorPos", LUA_OPCODE(Lua_V1, GetActorPos) },
00785     { "GetActorRect", LUA_OPCODE(Lua_V1, GetActorRect) },
00786     { "GetActorPuckVector", LUA_OPCODE(Lua_V1, GetActorPuckVector) },
00787     { "GetActorYawToPoint", LUA_OPCODE(Lua_V1, GetActorYawToPoint) },
00788     { "SetActorReflection", LUA_OPCODE(Lua_V1, SetActorReflection) },
00789     { "PutActorAtInterest", LUA_OPCODE(Lua_V1, PutActorAtInterest) },
00790     { "PutActorAt", LUA_OPCODE(Lua_V1, PutActorAt) },
00791     { "PutActorInSet", LUA_OPCODE(Lua_V1, PutActorInSet) },
00792     { "WalkActorVector", LUA_OPCODE(Lua_V1, WalkActorVector) },
00793     { "WalkActorForward", LUA_OPCODE(Lua_V1, WalkActorForward) },
00794     { "DriveActorTo", LUA_OPCODE(Lua_V1, DriveActorTo) },
00795     { "WalkActorTo", LUA_OPCODE(Lua_V1, WalkActorTo) },
00796     { "WalkActorToAvoiding", LUA_OPCODE(Lua_V1, WalkActorToAvoiding) },
00797     { "ActorLookAt", LUA_OPCODE(Lua_V1, ActorLookAt) },
00798     { "SetActorLookRate", LUA_OPCODE(Lua_V1, SetActorLookRate) },
00799     { "GetActorLookRate", LUA_OPCODE(Lua_V1, GetActorLookRate) },
00800     { "GetVisibleThings", LUA_OPCODE(Lua_V1, GetVisibleThings) },
00801     { "GetCameraActor", LUA_OPCODE(Lua_V1, GetCameraActor) },
00802     { "SetActorHead", LUA_OPCODE(Lua_V1, SetActorHead) },
00803     { "SetActorVisibility", LUA_OPCODE(Lua_V1, SetActorVisibility) },
00804     { "SetActorFollowBoxes", LUA_OPCODE(Lua_V1, SetActorFollowBoxes) },
00805     { "ShutUpActor", LUA_OPCODE(Lua_V1, ShutUpActor) },
00806     { "SetActorFrustrumCull", LUA_OPCODE(Lua_V1, SetActorFrustrumCull) },
00807     { "IsActorInSector", LUA_OPCODE(Lua_V1, IsActorInSector) },
00808     { "GetActorSector", LUA_OPCODE(Lua_V1, GetActorSector) },
00809     { "IsPointInSector", LUA_OPCODE(Lua_V1, IsPointInSector) },
00810     { "GetPointSector", LUA_OPCODE(Lua_V1, GetPointSector) },
00811     { "TurnActor", LUA_OPCODE(Lua_V1, TurnActor) },
00812     { "GetActorRot", LUA_OPCODE(Lua_V1, GetActorRot) },
00813     { "SetActorRot", LUA_OPCODE(Lua_V1, SetActorRot) },
00814     { "SetActorPitch", LUA_OPCODE(Lua_V1, SetActorPitch) },
00815     { "SetActorRoll", LUA_OPCODE(Lua_V1, SetActorRoll) },
00816     { "IsActorTurning", LUA_OPCODE(Lua_V1, IsActorTurning) },
00817     { "PlayActorChore", LUA_OPCODE(Lua_V1, PlayActorChore) },
00818     { "PlayActorChoreLooping", LUA_OPCODE(Lua_V1, PlayActorChoreLooping) },
00819     { "StopActorChore", LUA_OPCODE(Lua_V1, StopActorChore) },
00820     { "CompleteActorChore", LUA_OPCODE(Lua_V1, CompleteActorChore) },
00821     { "IsActorMoving", LUA_OPCODE(Lua_V1, IsActorMoving) },
00822     { "IsActorChoring", LUA_OPCODE(Lua_V1, IsActorChoring) },
00823     { "IsActorResting", LUA_OPCODE(Lua_V1, IsActorResting) },
00824     { "SetActorChoreLooping", LUA_OPCODE(Lua_V1, SetActorChoreLooping) },
00825     { "GetActorChores", LUA_OPCODE(Lua_V1, GetActorChores) },
00826     { "GetActorCostumeDepth", LUA_OPCODE(Lua_V1, GetActorCostumeDepth) },
00827     { "WorldToScreen", LUA_OPCODE(Lua_V1, WorldToScreen) },
00828     { "exit", LUA_OPCODE(Lua_V1, Exit) },
00829     { "FunctionName", LUA_OPCODE(Lua_V1, FunctionName) },
00830     { "EnableDebugKeys", LUA_OPCODE(Lua_V1, EnableDebugKeys) },
00831     { "LockFont", LUA_OPCODE(Lua_V1, LockFont) },
00832     { "EnableControl", LUA_OPCODE(Lua_V1, EnableControl) },
00833     { "DisableControl", LUA_OPCODE(Lua_V1, DisableControl) },
00834     { "GetControlState", LUA_OPCODE(Lua_V1, GetControlState) },
00835     { "PrintError", LUA_OPCODE(Lua_V1, PrintError) },
00836     { "PrintWarning", LUA_OPCODE(Lua_V1, PrintWarning) },
00837     { "PrintDebug", LUA_OPCODE(Lua_V1, PrintDebug) },
00838     { "MakeCurrentSet", LUA_OPCODE(Lua_V1, MakeCurrentSet) },
00839     { "LockSet", LUA_OPCODE(Lua_V1, LockSet) },
00840     { "UnLockSet", LUA_OPCODE(Lua_V1, UnLockSet) },
00841     { "MakeCurrentSetup", LUA_OPCODE(Lua_V1, MakeCurrentSetup) },
00842     { "GetCurrentSetup", LUA_OPCODE(Lua_V1, GetCurrentSetup) },
00843     { "NextSetup", LUA_OPCODE(Lua_V1, NextSetup) },
00844     { "PreviousSetup", LUA_OPCODE(Lua_V1, PreviousSetup) },
00845     { "StartFullscreenMovie", LUA_OPCODE(Lua_V1, StartFullscreenMovie) },
00846     { "IsFullscreenMoviePlaying", LUA_OPCODE(Lua_V1, IsFullscreenMoviePlaying) },
00847     { "StartMovie", LUA_OPCODE(Lua_V1, StartMovie) },
00848     { "StopMovie", LUA_OPCODE(Lua_V1, StopMovie) },
00849     { "PauseMovie", LUA_OPCODE(Lua_V1, PauseMovie) },
00850     { "IsMoviePlaying", LUA_OPCODE(Lua_V1, IsMoviePlaying) },
00851     { "PlaySound", LUA_OPCODE(Lua_V1, PlaySound) },
00852     { "PlaySoundAt", LUA_OPCODE(Lua_V1, PlaySoundAt) },
00853     { "IsSoundPlaying", LUA_OPCODE(Lua_V1, IsSoundPlaying) },
00854     { "SetSoundPosition", LUA_OPCODE(Lua_V1, SetSoundPosition) },
00855     { "FileFindFirst", LUA_OPCODE(Lua_V1, FileFindFirst) },
00856     { "FileFindNext", LUA_OPCODE(Lua_V1, FileFindNext) },
00857     { "FileFindDispose", LUA_OPCODE(Lua_V1, FileFindDispose) },
00858     { "InputDialog", LUA_OPCODE(Lua_V1, InputDialog) },
00859     { "WriteRegistryValue", LUA_OPCODE(Lua_V1, WriteRegistryValue) },
00860     { "ReadRegistryValue", LUA_OPCODE(Lua_V1, ReadRegistryValue) },
00861     { "GetSectorOppositeEdge", LUA_OPCODE(Lua_V1, GetSectorOppositeEdge) },
00862     { "MakeSectorActive", LUA_OPCODE(Lua_V1, MakeSectorActive) },
00863     { "PreRender", LUA_OPCODE(Lua_V1, PreRender) },
00864     { "SpewStartup", LUA_OPCODE(Lua_V1, SpewStartup) },
00865     { "GetCurrentScript", LUA_OPCODE(Lua_V1, GetCurrentScript) },
00866     { "PrintActorCostumes", LUA_OPCODE(Lua_V1, PrintActorCostumes) },
00867     { "PushActorCostume", LUA_OPCODE(Lua_V1, PushActorCostume) },
00868     { "PopActorCostume", LUA_OPCODE(Lua_V1, PopActorCostume) },
00869     { "LoadCostume", LUA_OPCODE(Lua_V1, LoadCostume) },
00870     { "RotateVector", LUA_OPCODE(Lua_V1, RotateVector) },
00871     { "GetCameraPosition", LUA_OPCODE(Lua_V1, GetCameraPosition) },
00872     { "SetCameraPosition", LUA_OPCODE(Lua_V1, SetCameraPosition) },
00873     { "SetCameraInterest", LUA_OPCODE(Lua_V1, SetCameraInterest) },
00874     { "GetCameraFOV", LUA_OPCODE(Lua_V1, GetCameraFOV) },
00875     { "SetCameraFOV", LUA_OPCODE(Lua_V1, SetCameraFOV) },
00876     { "GetCameraRoll", LUA_OPCODE(Lua_V1, GetCameraRoll) },
00877     { "SetCameraRoll", LUA_OPCODE(Lua_V1, SetCameraRoll) },
00878     { "GetCameraLookVector", LUA_OPCODE(Lua_V1, GetCameraLookVector) },
00879     { "PointActorAt", LUA_OPCODE(Lua_V1, PointActorAt) },
00880     { "TurnActorTo", LUA_OPCODE(Lua_V1, TurnActorTo) },
00881     { "PerSecond", LUA_OPCODE(Lua_V1, PerSecond) },
00882     { "GetAngleBetweenVectors", LUA_OPCODE(Lua_V1, GetAngleBetweenVectors) },
00883     { "GetAngleBetweenActors", LUA_OPCODE(Lua_V1, GetAngleBetweenActors) },
00884     { "SetAmbientLight", LUA_OPCODE(Lua_V1, SetAmbientLight) },
00885     { "TurnLightOn", LUA_OPCODE(Lua_V1, TurnLightOn) },
00886     { "SetLightPosition", LUA_OPCODE(Lua_V1, SetLightPosition) },
00887     { "SetLightIntensity", LUA_OPCODE(Lua_V1, SetLightIntensity) },
00888     { "LightMgrSetChange", LUA_OPCODE(Lua_V1, LightMgrSetChange) },
00889     { "LightMgrStartup", LUA_OPCODE(Lua_V1, LightMgrStartup) },
00890     { "ImStartSound", LUA_OPCODE(Lua_V1, ImStartSound) },
00891     { "ImStopSound", LUA_OPCODE(Lua_V1, ImStopSound) },
00892     { "ImStopAllSounds", LUA_OPCODE(Lua_V1, ImStopAllSounds) },
00893     { "ImGetParam", LUA_OPCODE(Lua_V1, ImGetParam) },
00894     { "ImSetParam", LUA_OPCODE(Lua_V1, ImSetParam) },
00895     { "ImFadeParam", LUA_OPCODE(Lua_V1, ImFadeParam) },
00896     { "ImGetSfxVol", LUA_OPCODE(Lua_V1, ImGetSfxVol) },
00897     { "ImSetSfxVol", LUA_OPCODE(Lua_V1, ImSetSfxVol) },
00898     { "ImGetVoiceVol", LUA_OPCODE(Lua_V1, ImGetVoiceVol) },
00899     { "ImSetVoiceVol", LUA_OPCODE(Lua_V1, ImSetVoiceVol) },
00900     { "ImGetMusicVol", LUA_OPCODE(Lua_V1, ImGetMusicVol) },
00901     { "ImSetMusicVol", LUA_OPCODE(Lua_V1, ImSetMusicVol) },
00902     { "ImSetState", LUA_OPCODE(Lua_V1, ImSetState) },
00903     { "ImSetSequence", LUA_OPCODE(Lua_V1, ImSetSequence) },
00904     { "ImPause", LUA_OPCODE(Lua_V1, ImPause) },
00905     { "ImResume", LUA_OPCODE(Lua_V1, ImResume) },
00906     { "ImSetVoiceEffect", LUA_OPCODE(Lua_V1, ImSetVoiceEffect) },
00907     { "LoadBundle", LUA_OPCODE(Lua_V1, LoadBundle) },
00908     { "SetGamma", LUA_OPCODE(Lua_V1, SetGamma) },
00909     { "SetActorWalkDominate", LUA_OPCODE(Lua_V1, SetActorWalkDominate) },
00910     { "SetActorConstrain", LUA_OPCODE(Lua_V1, SetActorConstrain) },
00911     { "RenderModeUser", LUA_OPCODE(Lua_V1, RenderModeUser) },
00912     { "ForceRefresh", LUA_OPCODE(Lua_V1, ForceRefresh) },
00913     { "DimScreen", LUA_OPCODE(Lua_V1, DimScreen) },
00914     { "DimRegion", LUA_OPCODE(Lua_V1, DimRegion) },
00915     { "CleanBuffer", LUA_OPCODE(Lua_V1, CleanBuffer) },
00916     { "Display", LUA_OPCODE(Lua_V1, Display) },
00917     { "SetSpeechMode", LUA_OPCODE(Lua_V1, SetSpeechMode) },
00918     { "GetSpeechMode", LUA_OPCODE(Lua_V1, GetSpeechMode) },
00919     { "SetShadowColor", LUA_OPCODE(Lua_V1, SetShadowColor) },
00920     { "ActivateActorShadow", LUA_OPCODE(Lua_V1, ActivateActorShadow) },
00921     { "SetActorShadowPlane", LUA_OPCODE(Lua_V1, SetActorShadowPlane) },
00922     { "SetActorShadowPoint", LUA_OPCODE(Lua_V1, SetActorShadowPoint) },
00923     { "SetActiveShadow", LUA_OPCODE(Lua_V1, SetActiveShadow) },
00924     { "KillActorShadows", LUA_OPCODE(Lua_V1, KillActorShadows) },
00925     { "AddShadowPlane", LUA_OPCODE(Lua_V1, AddShadowPlane) },
00926     { "SetActorShadowValid", LUA_OPCODE(Lua_V1, SetActorShadowValid) },
00927     { "FreeObjectState", LUA_OPCODE(Lua_V1, FreeObjectState) },
00928     { "NewObjectState", LUA_OPCODE(Lua_V1, NewObjectState) },
00929     { "SetObjectType", LUA_OPCODE(Lua_V1, SetObjectType) },
00930     { "SendObjectToBack", LUA_OPCODE(Lua_V1, SendObjectToBack) },
00931     { "SendObjectToFront", LUA_OPCODE(Lua_V1, SendObjectToFront) },
00932     { "ActorToClean", LUA_OPCODE(Lua_V1, ActorToClean) },
00933     { "FlushControls", LUA_OPCODE(Lua_V1, FlushControls) },
00934     { "SetActorCollisionMode", LUA_OPCODE(Lua_V1, SetActorCollisionMode) },
00935     { "SetActorCollisionScale", LUA_OPCODE(Lua_V1, SetActorCollisionScale) },
00936     { "SetActorClipActive", LUA_OPCODE(Lua_V1, SetActorClipActive) },
00937     { "SetActorClipPlane", LUA_OPCODE(Lua_V1, SetActorClipPlane) },
00938     { "FadeOutChore", LUA_OPCODE(Lua_V1, FadeOutChore) },
00939     { "FadeInChore", LUA_OPCODE(Lua_V1, FadeInChore) },
00940     { "IrisDown", LUA_OPCODE(Lua_V1, IrisDown) },
00941     { "IrisUp", LUA_OPCODE(Lua_V1, IrisUp) },
00942     { "TextFileGetLineCount", LUA_OPCODE(Lua_V1, TextFileGetLineCount) },
00943     { "TextFileGetLine", LUA_OPCODE(Lua_V1, TextFileGetLine) },
00944     { "ScreenShot", LUA_OPCODE(Lua_V1, ScreenShot) },
00945     { "GetSaveGameImage", LUA_OPCODE(Lua_V1, GetSaveGameImage) },
00946     { "GetImage", LUA_OPCODE(Lua_V1, GetImage) },
00947     { "FreeImage", LUA_OPCODE(Lua_V1, FreeImage) },
00948     { "BlastImage", LUA_OPCODE(Lua_V1, BlastImage) },
00949     { "BlastRect", LUA_OPCODE(Lua_V1, BlastRect) },
00950     { "SubmitSaveGameData", LUA_OPCODE(Lua_V1, SubmitSaveGameData) },
00951     { "GetSaveGameData", LUA_OPCODE(Lua_V1, GetSaveGameData) },
00952     { "SetTextSpeed", LUA_OPCODE(Lua_V1, SetTextSpeed) },
00953     { "GetTextSpeed", LUA_OPCODE(Lua_V1, GetTextSpeed) },
00954     { "DetachFromResources", LUA_OPCODE(Lua_V1, DetachFromResources) },
00955     { "AttachToResources", LUA_OPCODE(Lua_V1, AttachToResources) },
00956     { "ActorPuckOrient", LUA_OPCODE(Lua_V1, ActorPuckOrient) },
00957     { "JustLoaded", LUA_OPCODE(Lua_V1, JustLoaded) },
00958     { "ResetTextures", LUA_OPCODE(Lua_V1, ResetTextures) },
00959     { "ShrinkBoxes", LUA_OPCODE(Lua_V1, ShrinkBoxes) },
00960     { "UnShrinkBoxes", LUA_OPCODE(Lua_V1, UnShrinkBoxes) },
00961     { "GetShrinkPos", LUA_OPCODE(Lua_V1, GetShrinkPos) },
00962     { "NukeResources", LUA_OPCODE(Lua_V1, NukeResources) },
00963     { "SetActorInvClipNode", LUA_OPCODE(Lua_V1, SetActorInvClipNode) },
00964     { "GetDiskFreeSpace", LUA_OPCODE(Lua_V1, GetDiskFreeSpace) },
00965     { "SaveIMuse", LUA_OPCODE(Lua_V1, SaveIMuse) },
00966     { "RestoreIMuse", LUA_OPCODE(Lua_V1, RestoreIMuse) },
00967     { "GetMemoryUsage", LUA_OPCODE(Lua_V1, GetMemoryUsage) },
00968     { "dofile", LUA_OPCODE(Lua_V1, new_dofile) },
00969 };
00970 
00971 static struct luaL_reg grimTextOpcodes[] = {
00972     { "IsMessageGoing", LUA_OPCODE(Lua_V1, IsMessageGoing) },
00973     { "SetSayLineDefaults", LUA_OPCODE(Lua_V1, SetSayLineDefaults) },
00974     { "SetActorTalkColor", LUA_OPCODE(Lua_V1, SetActorTalkColor) },
00975     { "GetActorTalkColor", LUA_OPCODE(Lua_V1, GetActorTalkColor) },
00976     { "SayLine", LUA_OPCODE(Lua_V1, SayLine) },
00977     { "PrintLine", LUA_OPCODE(Lua_V1, PrintLine) },
00978     { "MakeTextObject", LUA_OPCODE(Lua_V1, MakeTextObject) },
00979     { "GetTextObjectDimensions", LUA_OPCODE(Lua_V1, GetTextObjectDimensions) },
00980     { "GetFontDimensions", LUA_OPCODE(Lua_V1, GetFontDimensions) },
00981     { "ChangeTextObject", LUA_OPCODE(Lua_V1, ChangeTextObject) },
00982     { "KillTextObject", LUA_OPCODE(Lua_V1, KillTextObject) },
00983     { "BlastText", LUA_OPCODE(Lua_V1, BlastText) },
00984     { "ExpireText", LUA_OPCODE(Lua_V1, ExpireText) },
00985     { "PurgeText", LUA_OPCODE(Lua_V1, PurgeText) },
00986     { "MakeColor", LUA_OPCODE(Lua_V1, MakeColor) },
00987     { "GetColorComponents", LUA_OPCODE(Lua_V1, GetColorComponents) },
00988     { "SetTranslationMode", LUA_OPCODE(Lua_V1, SetTranslationMode) },
00989     { "GetTranslationMode", LUA_OPCODE(Lua_V1, GetTranslationMode) },
00990     { "GetTextCharPosition", LUA_OPCODE(Lua_V1, GetTextCharPosition) },
00991     { "LocalizeString", LUA_OPCODE(Lua_V1, LocalizeString) },
00992     { "SetEmergencyFont", LUA_OPCODE(Lua_V1, SetEmergencyFont) },
00993     { "SetOffscreenTextPos", LUA_OPCODE(Lua_V1, SetOffscreenTextPos) }
00994 };
00995 
00996 struct luaL_reg grimPrimitivesOpcodes[] = {
00997     { "DrawLine", LUA_OPCODE(Lua_V1, DrawLine) },
00998     { "DrawPolygon", LUA_OPCODE(Lua_V1, DrawPolygon) },
00999     { "DrawRectangle", LUA_OPCODE(Lua_V1, DrawRectangle) },
01000     { "ChangePrimitive", LUA_OPCODE(Lua_V1, ChangePrimitive) },
01001     { "KillPrimitive", LUA_OPCODE(Lua_V1, KillPrimitive) },
01002     { "PurgePrimitiveQueue", LUA_OPCODE(Lua_V1, PurgePrimitiveQueue) }
01003 };
01004 
01005 struct luaL_reg grimHardwareOpcodes[] = {
01006     { "Is3DHardwareEnabled", LUA_OPCODE(Lua_V1, Is3DHardwareEnabled) },
01007     { "GetVideoDevices", LUA_OPCODE(Lua_V1, GetVideoDevices) },
01008     { "SetVideoDevices", LUA_OPCODE(Lua_V1, SetVideoDevices) },
01009     { "SetHardwareState", LUA_OPCODE(Lua_V1, SetHardwareState) },
01010     { "Enumerate3DDevices", LUA_OPCODE(Lua_V1, Enumerate3DDevices) },
01011     { "EnumerateVideoDevices", LUA_OPCODE(Lua_V1, EnumerateVideoDevices) }
01012 };
01013 
01014 void Lua_V1::registerOpcodes() {
01015     // Register main opcodes functions
01016     luaL_openlib(grimMainOpcodes, ARRAYSIZE(grimMainOpcodes));
01017 
01018     // Register text opcodes functions
01019     luaL_openlib(grimTextOpcodes, ARRAYSIZE(grimTextOpcodes));
01020 
01021     // Register primitives opcodeEs functions
01022     luaL_openlib(grimPrimitivesOpcodes, ARRAYSIZE(grimPrimitivesOpcodes));
01023 
01024     // Register hardware opcode functions
01025     luaL_openlib(grimHardwareOpcodes, ARRAYSIZE(grimHardwareOpcodes));
01026 
01027     LuaBase::registerOpcodes();
01028 }
01029 
01030 void Lua_V1::boot() {
01031     // The default value of these globals, defined in _controls.lua, is 256, 257, 258, 259.
01032     // These values clash with the numpad 0, 1, 2 and 3 keycodes, so we set them here.
01033     lua_pushnumber(KEYCODE_JOY1_HLEFT);
01034     lua_setglobal("JOYSTICK_X_LEFT");
01035 
01036     lua_pushnumber(KEYCODE_JOY1_HRIGHT);
01037     lua_setglobal("JOYSTICK_X_RIGHT");
01038 
01039     lua_pushnumber(KEYCODE_JOY1_HUP);
01040     lua_setglobal("JOYSTICK_Y_UP");
01041 
01042     lua_pushnumber(KEYCODE_JOY1_HDOWN);
01043     lua_setglobal("JOYSTICK_Y_DOWN");
01044 
01045     LuaBase::boot();
01046 }
01047 
01048 void Lua_V1::postRestoreHandle() {
01049 
01050     if (g_grim->getGameType() == GType_GRIM) {
01051         lua_beginblock();
01052         // Set the developerMode, since the save contains the value of
01053         // the installation it was made with.
01054         lua_pushobject(lua_getglobal("developerMode"));
01055         bool devMode = g_registry->getBool("good_times");
01056         pushbool(devMode);
01057         lua_setglobal("developerMode");
01058         lua_endblock();
01059     }
01060 
01061     // Starting a movie calls the function 'music_state.pause()', which saves the current sfx volume to a temp
01062     // variable and sets it to 0. When the movie finishes 'music_state.unpause()' will be called, which reads
01063     // the volume from the temp variable and sets it. But if we have modified the sfx volume in the options
01064     // and than load a savegame made during a movie, at the end of the movie the temp variable will have the
01065     // old value. So here we call 'music_state.pause()' again, so that it can set the right value to the
01066     // temp variable.
01067     lua_beginblock();
01068     lua_Object o = lua_getglobal("music_state");
01069     if (!lua_isnil(o)) {
01070         lua_pushobject(o);
01071         lua_pushstring("paused");
01072         if (!lua_isnil(lua_gettable())) {
01073             lua_pushobject(o);
01074             lua_pushstring("paused");
01075             pushbool(false);
01076             lua_settable();
01077 
01078             lua_pushobject(o);
01079             lua_pushstring("pause");
01080             lua_Object func = lua_gettable();
01081             lua_pushobject(o);
01082             lua_callfunction(func);
01083         }
01084     }
01085     lua_endblock();
01086 }
01087 
01088 } // end of namespace Grim


Generated on Sat Sep 14 2019 05:01:15 for ResidualVM by doxygen 1.7.1
curved edge   curved edge