ScummVM API documentation
lua-script.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef HDB_LUA_SCRIPT_H
23 #define HDB_LUA_SCRIPT_H
24 
25 struct lua_State;
26 
27 namespace HDB {
28 
29 struct Global {
30  char global[32]; // name of global variable
31  int valueOrString; // value = 0, string = 1
32  double value; // value
33  char string[32]; // string
34 
35  Global() : valueOrString(0), value(0) {
36  global[0] = 0;
37  string[0] = 0;
38  }
39 };
40 
41 class LuaScript {
42 public:
43  LuaScript();
44  ~LuaScript();
45 
46  bool loadLua(const char *name);
47  void saveGlobalNumber(const char *global, double value);
48  void saveGlobalString(const char *global, const char *string);
49  void loadGlobal(const char *global);
50  void purgeGlobals();
51  void save(Common::OutSaveFile *out);
52  void loadSaveFile(Common::InSaveFile *in);
53 
54  void init();
55  bool initScript(Common::SeekableReadStream *stream, const char *scriptName, int32 length);
56 
57  void pushInt(int value);
58  void pushString(char *string);
59  void pushFunction(char *func);
60  void call(int args, int returns);
61  bool callFunction(const char *name, int returns);
62  void invokeLuaFunction(char *luaFunc, int x, int y, int value1, int value2);
63 
64  bool executeMPC(Common::SeekableReadStream *stream, const char *name, const char *scriptName, int32 length);
65  bool executeFile(const Common::String &filename);
66  bool executeChunk(Common::String &chunk, const Common::String &chunkName) const;
67  void checkParameters(const char *func, int params);
68 
69  const char *getStringOffStack();
70 
71  void setLuaGlobalValue(const char *name, int value);
72  bool isValid() {
73  return _systemInit;
74  }
75 
76  // Platform-specific Constants
77  int _cameraXOff;
78  int _cameraYOff;
79 
80 private:
81  lua_State *_state;
82  int _pcallErrorhandlerRegistryIndex;
83 
84  Common::SeekableReadStream* _globalLuaStream;
85  int32 _globalLuaLength;
86  bool _systemInit;
87 
88  bool registerExtensions();
89  void stripComments(char *chunk);
90  void addPatches(Common::String &chunk, const char *scriptName);
91 
92  Common::Array<Global *> _globals;
93 };
94 
95 void lua_printstack(lua_State *L);
96 
97 }
98 
99 #endif // !HDB_LUA_SCRIPT_H
Definition: ai-player.h:25
Definition: str.h:59
Definition: savefile.h:54
Definition: array.h:52
Definition: lstate.h:100
Definition: stream.h:745
Definition: lua-script.h:29
Definition: lua-script.h:41