2019-06-02 18:41:05 +05:30
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/file.h"
|
|
|
|
|
2019-06-05 14:12:53 +05:30
|
|
|
#include "hdb/hdb.h"
|
2019-06-02 18:41:05 +05:30
|
|
|
|
|
|
|
#ifndef HDB_LUA_SCRIPT_H
|
|
|
|
#define HDB_LUA_SCRIPT_H
|
|
|
|
|
|
|
|
struct lua_State;
|
|
|
|
|
|
|
|
namespace HDB {
|
|
|
|
|
2019-06-24 02:14:08 +05:30
|
|
|
enum {
|
|
|
|
kCameraXOff = (32 * 3 + 24), // 3.75 Tiles Extra
|
|
|
|
kCameraYOff = (32 * 2 + 16) // 2.50 Tiles Extra
|
|
|
|
};
|
|
|
|
|
2019-07-09 00:18:01 +05:30
|
|
|
struct Global {
|
|
|
|
char global[32]; // name of global variable
|
|
|
|
int valueOrString; // value = 0, string = 1
|
|
|
|
double value; // value
|
|
|
|
char string[32]; // string
|
|
|
|
|
|
|
|
Global() : valueOrString(0), value(0) {
|
|
|
|
global[0] = 0;
|
|
|
|
string[0] = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-02 18:41:05 +05:30
|
|
|
class LuaScript {
|
|
|
|
public:
|
|
|
|
LuaScript();
|
|
|
|
~LuaScript();
|
|
|
|
|
2019-07-03 17:31:10 +02:00
|
|
|
bool loadLua(const char *name);
|
2019-07-09 00:18:01 +05:30
|
|
|
void saveGlobalNumber(const char *global, double value);
|
|
|
|
void saveGlobalString(const char *global, const char *string);
|
|
|
|
void loadGlobal(const char *global);
|
|
|
|
void purgeGlobals();
|
2019-07-17 12:13:48 +02:00
|
|
|
void save(Common::OutSaveFile *out, int slot);
|
2019-07-09 00:21:43 +05:30
|
|
|
void loadSaveFile(Common::InSaveFile *in, const char *fName);
|
2019-07-03 17:01:00 +02:00
|
|
|
|
2019-06-02 18:41:05 +05:30
|
|
|
bool init();
|
2019-06-06 18:51:53 +05:30
|
|
|
bool initScript(Common::SeekableReadStream *stream, const char *scriptName, int32 length);
|
2019-06-27 07:10:08 +05:30
|
|
|
|
|
|
|
void pushInt(int value);
|
|
|
|
void pushString(char *string);
|
|
|
|
void pushFunction(char *func);
|
|
|
|
void call(int args, int returns);
|
2019-06-18 04:14:45 +05:30
|
|
|
bool callFunction(const char *name, int returns);
|
2019-06-27 07:39:50 +05:30
|
|
|
void invokeLuaFunction(char *luaFunc, int x, int y, int value1, int value2);
|
2019-06-27 07:10:08 +05:30
|
|
|
|
2019-06-06 18:51:53 +05:30
|
|
|
bool executeMPC(Common::SeekableReadStream *stream, const char *name, const char *scriptName, int32 length);
|
2019-06-02 18:41:05 +05:30
|
|
|
bool executeFile(const Common::String &filename);
|
2019-07-05 15:47:43 +02:00
|
|
|
bool executeChunk(Common::String &chunk, const Common::String &chunkName) const;
|
2019-06-18 19:45:44 +05:30
|
|
|
void checkParameters(const char *func, int params);
|
2019-06-02 18:41:05 +05:30
|
|
|
|
2019-06-20 01:45:51 +05:30
|
|
|
const char *getStringOffStack();
|
|
|
|
|
2019-07-03 17:01:00 +02:00
|
|
|
void setLuaGlobalValue(const char *name, int value);
|
2019-07-10 20:15:08 +05:30
|
|
|
bool isValid() {
|
|
|
|
return _systemInit;
|
|
|
|
}
|
2019-07-03 17:01:00 +02:00
|
|
|
|
2019-06-02 18:41:05 +05:30
|
|
|
private:
|
|
|
|
lua_State *_state;
|
2019-06-06 01:22:09 +02:00
|
|
|
int _pcallErrorhandlerRegistryIndex;
|
|
|
|
|
2019-06-06 03:41:38 +05:30
|
|
|
Common::SeekableReadStream* _globalLuaStream;
|
|
|
|
int32 _globalLuaLength;
|
2019-06-02 19:03:34 +05:30
|
|
|
bool _systemInit;
|
2019-06-02 18:41:05 +05:30
|
|
|
|
2019-06-05 01:10:57 +05:30
|
|
|
bool registerExtensions();
|
2019-06-06 20:17:54 +05:30
|
|
|
void stripComments(char *chunk);
|
2019-06-06 18:51:53 +05:30
|
|
|
void addPatches(Common::String &chunk, const char *scriptName);
|
2019-07-09 00:18:01 +05:30
|
|
|
|
|
|
|
Common::Array<Global *> _globals;
|
2019-06-02 18:41:05 +05:30
|
|
|
};
|
|
|
|
|
2019-06-20 12:38:32 +02:00
|
|
|
void lua_printstack(lua_State *L);
|
|
|
|
|
2019-06-02 18:41:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !HDB_LUA_SCRIPT_H
|