ScummVM API documentation
lua.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 GRIM_LUABASE_H
23 #define GRIM_LUABASE_H
24 
25 #include "common/str.h"
26 #include "common/list.h"
27 
28 #include "engines/grim/color.h"
29 
30 namespace Grim {
31 
32 typedef uint32 lua_Object; // from lua/lua.h
33 
34 class Actor;
35 class Bitmap;
36 class Costume;
37 class Font;
38 class ObjectState;
39 class PrimitiveObject;
40 class TextObject;
41 class TextObjectDefaults;
42 class TextObjectCommon;
43 class PoolObjectBase;
44 
48 #define DECLARE_LUA_OPCODE(func) \
49  public:\
50  inline static void static_##func() {\
51  static_cast<LuaClass *>(LuaBase::instance())->func();\
52  }\
53  protected:\
54  virtual void func()
55 
58 #define LUA_OPCODE(class, func) \
59  class::static_##func
60 
64 void lua_PatchGrimSave();
65 
72 class LuaObjects {
73 public:
74  void add(float number);
75  void add(int number);
76  void add(const PoolObjectBase *obj);
77  void add(const char *str);
78  void addNil();
79 
80 private:
84  void pushObjects() const;
85 
89  struct Obj {
90  enum {
91  Nil,
92  Number,
93  Object,
94  String
95  } _type;
96  union {
97  float number;
98  const PoolObjectBase *object;
99  const char *string;
100  } _value;
101  };
102  Common::List<Obj> _objects;
103 
104  friend class LuaBase;
105 };
106 
107 class LuaBase {
108 public:
109  typedef LuaBase LuaClass;
110 
111  LuaBase();
112  virtual ~LuaBase();
113  inline static LuaBase *instance() { return s_instance; }
114 
115  int dofile(const char *filename);
116 
117  virtual bool findCostume(lua_Object costumeObj, Actor *actor, Costume **costume);
118  virtual Common::String parseMsgText(const char *msg, char *msgId);
119  virtual void parseSayLineTable(lua_Object paramObj, bool *background, int *vol, int *pan, float *x, float *y);
120  virtual void setTextObjectParams(TextObjectCommon *textObject, lua_Object tableObj);
121 
122  void update(int frameTime, int movieTime);
123  void setFrameTime(float frameTime);
124  void setMovieTime(float movieTime);
125  virtual void registerLua();
126  virtual void registerOpcodes();
127  virtual void loadSystemScript();
128  virtual void boot();
129  virtual void postRestoreHandle() { }
130 
131  // Force the demo flag
132  virtual void forceDemo();
133 
139  bool callback(const char *name);
146  bool callback(const char *name, const LuaObjects &objects);
147 
148 protected:
149  bool getbool(int num);
150  void pushbool(bool val);
151  void pushobject(const PoolObjectBase *o);
152  int getobject(lua_Object obj);
153  Actor *getactor(lua_Object obj);
154  Bitmap *getbitmap(lua_Object obj);
155  TextObject *gettextobject(lua_Object obj);
156  Font *getfont(lua_Object obj);
157  Color getcolor(lua_Object obj);
158  PrimitiveObject *getprimitive(lua_Object obj);
159  ObjectState *getobjectstate(lua_Object obj);
160  // 0 - translate from '/msgId/'
161  // 1 - don't translate - message after '/msgId'
162  // 2 - return '/msgId/'
163  int _translationMode;
164 
165  DECLARE_LUA_OPCODE(dummyHandler);
166  DECLARE_LUA_OPCODE(typeOverride);
167  DECLARE_LUA_OPCODE(concatFallback);
168 
169 private:
170  unsigned int _frameTimeCollection;
171 
172  int refSystemTable;
173  int refTypeOverride;
174  int refOldConcatFallback;
175  int refTextObjectX;
176  int refTextObjectY;
177  int refTextObjectFont;
178  int refTextObjectWidth;
179  int refTextObjectHeight;
180  int refTextObjectFGColor;
181  int refTextObjectBGColor;
182  int refTextObjectFXColor;
183  int refTextObjectHIColor;
184  int refTextObjectDuration;
185  int refTextObjectCenter;
186  int refTextObjectLJustify;
187  int refTextObjectRJustify;
188  int refTextObjectVolume;
189  int refTextObjectBackground;
190  int refTextObjectPan;
191  int refTextObjectLayer;
192  int refTextObjectCoords;
193 
194  static LuaBase *s_instance;
195 
196  friend class LuaObjects;
197 };
198 
199 } // end of namespace Grim
200 
201 #endif
Definition: str.h:59
A list of arguments to be passed to a Lua function.
Definition: lua.h:72
Definition: objectstate.h:34
Definition: actor.h:33
Definition: bitmap.h:125
Definition: textobject.h:84
Definition: textobject.h:35
Definition: primitives.h:34
Definition: font.h:38
Actor represents a 3D character on screen.
Definition: actor.h:72
Definition: lua.h:107
Definition: pool.h:34
Definition: object.h:32
Definition: color.h:29
Definition: costume.h:45