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 
67 class LuaObjects {
68 public:
69  void add(float number);
70  void add(int number);
71  void add(const PoolObjectBase *obj);
72  void add(const char *str);
73  void addNil();
74 
75 private:
79  void pushObjects() const;
80 
84  struct Obj {
85  enum {
86  Nil,
87  Number,
88  Object,
89  String
90  } _type;
91  union {
92  float number;
93  const PoolObjectBase *object;
94  const char *string;
95  } _value;
96  };
97  Common::List<Obj> _objects;
98 
99  friend class LuaBase;
100 };
101 
102 class LuaBase {
103 public:
104  typedef LuaBase LuaClass;
105 
106  LuaBase();
107  virtual ~LuaBase();
108  inline static LuaBase *instance() { return s_instance; }
109 
110  int dofile(const char *filename);
111 
112  virtual bool findCostume(lua_Object costumeObj, Actor *actor, Costume **costume);
113  virtual Common::String parseMsgText(const char *msg, char *msgId);
114  virtual void parseSayLineTable(lua_Object paramObj, bool *background, int *vol, int *pan, float *x, float *y);
115  virtual void setTextObjectParams(TextObjectCommon *textObject, lua_Object tableObj);
116 
117  void update(int frameTime, int movieTime);
118  void setFrameTime(float frameTime);
119  void setMovieTime(float movieTime);
120  virtual void registerLua();
121  virtual void registerOpcodes();
122  virtual void loadSystemScript();
123  virtual void boot();
124  virtual void postRestoreHandle() { }
125 
126  // Force the demo flag
127  virtual void forceDemo();
128 
134  bool callback(const char *name);
141  bool callback(const char *name, const LuaObjects &objects);
142 
143 protected:
144  bool getbool(int num);
145  void pushbool(bool val);
146  void pushobject(const PoolObjectBase *o);
147  int getobject(lua_Object obj);
148  Actor *getactor(lua_Object obj);
149  Bitmap *getbitmap(lua_Object obj);
150  TextObject *gettextobject(lua_Object obj);
151  Font *getfont(lua_Object obj);
152  Color getcolor(lua_Object obj);
153  PrimitiveObject *getprimitive(lua_Object obj);
154  ObjectState *getobjectstate(lua_Object obj);
155  // 0 - translate from '/msgId/'
156  // 1 - don't translate - message after '/msgId'
157  // 2 - return '/msgId/'
158  int _translationMode;
159 
160  DECLARE_LUA_OPCODE(dummyHandler);
161  DECLARE_LUA_OPCODE(typeOverride);
162  DECLARE_LUA_OPCODE(concatFallback);
163 
164 private:
165  unsigned int _frameTimeCollection;
166 
167  int refSystemTable;
168  int refTypeOverride;
169  int refOldConcatFallback;
170  int refTextObjectX;
171  int refTextObjectY;
172  int refTextObjectFont;
173  int refTextObjectWidth;
174  int refTextObjectHeight;
175  int refTextObjectFGColor;
176  int refTextObjectBGColor;
177  int refTextObjectFXColor;
178  int refTextObjectHIColor;
179  int refTextObjectDuration;
180  int refTextObjectCenter;
181  int refTextObjectLJustify;
182  int refTextObjectRJustify;
183  int refTextObjectVolume;
184  int refTextObjectBackground;
185  int refTextObjectPan;
186  int refTextObjectLayer;
187  int refTextObjectCoords;
188 
189  static LuaBase *s_instance;
190 
191  friend class LuaObjects;
192 };
193 
194 } // end of namespace Grim
195 
196 #endif
Definition: str.h:59
A list of arguments to be passed to a Lua function.
Definition: lua.h:67
Definition: objectstate.h:34
Definition: actor.h:33
Definition: bitmap.h:126
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:102
Definition: pool.h:34
Definition: object.h:32
Definition: color.h:29
Definition: costume.h:45