2009-05-26 14:13:08 +00:00
|
|
|
/* Residual - A 3D game interpreter
|
2008-06-13 14:57:47 +00:00
|
|
|
*
|
|
|
|
* Residual is the legal property of its developers, whose names
|
2011-04-16 12:12:44 +00:00
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
2008-06-13 14:57:47 +00:00
|
|
|
* file distributed with this source distribution.
|
2006-04-02 14:20:45 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2011-10-13 18:42:09 +00:00
|
|
|
#ifndef GRIM_LUABASE_H
|
|
|
|
#define GRIM_LUABASE_H
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2011-10-13 18:25:50 +00:00
|
|
|
#include "common/str.h"
|
|
|
|
#include "common/list.h"
|
2009-05-09 17:44:05 +00:00
|
|
|
|
2009-05-25 06:49:57 +00:00
|
|
|
namespace Grim {
|
|
|
|
|
2011-10-13 18:25:50 +00:00
|
|
|
typedef uint32 lua_Object; // from lua/lua.h
|
|
|
|
|
2011-05-08 05:28:46 +00:00
|
|
|
class Actor;
|
2011-09-07 21:08:59 +00:00
|
|
|
class PoolColor;
|
2011-05-08 10:29:41 +00:00
|
|
|
class Costume;
|
2011-05-08 05:28:46 +00:00
|
|
|
class Font;
|
|
|
|
class ObjectState;
|
|
|
|
class PrimitiveObject;
|
|
|
|
class TextObject;
|
2011-05-18 01:03:17 +00:00
|
|
|
class TextObjectDefaults;
|
|
|
|
class TextObjectCommon;
|
2011-09-07 21:08:59 +00:00
|
|
|
class PoolObjectBase;
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2011-10-13 18:42:09 +00:00
|
|
|
/**
|
|
|
|
* Declare a Lua opcode in the current class.
|
|
|
|
*/
|
2011-10-12 15:42:40 +00:00
|
|
|
#define DECLARE_LUA_OPCODE(func) \
|
2011-10-13 18:42:09 +00:00
|
|
|
public:\
|
2011-10-12 15:42:40 +00:00
|
|
|
inline static void static_##func() {\
|
|
|
|
static_cast<LuaClass *>(LuaBase::instance())->func();\
|
|
|
|
}\
|
2011-10-13 18:42:09 +00:00
|
|
|
protected:\
|
2011-10-12 15:42:40 +00:00
|
|
|
virtual void func()
|
2011-10-13 18:42:09 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the opcode "func" of the class "class".
|
|
|
|
*/
|
2011-10-12 15:42:40 +00:00
|
|
|
#define LUA_OPCODE(class, func) \
|
|
|
|
class::static_##func
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2011-10-13 18:42:09 +00:00
|
|
|
/**
|
|
|
|
* @brief A list of arguments to be passed to a Lua function.
|
|
|
|
*
|
|
|
|
* This is a convenience class to pass arguments to a Lua function, using
|
|
|
|
* LuaBase::callback(const char *name, const LuaObjects &objects).
|
|
|
|
*/
|
2011-10-13 18:25:50 +00:00
|
|
|
class LuaObjects {
|
|
|
|
public:
|
|
|
|
void add(float number);
|
|
|
|
void add(int number);
|
|
|
|
void add(const PoolObjectBase *obj);
|
|
|
|
void add(const char *str);
|
|
|
|
void addNil();
|
|
|
|
|
2011-10-13 18:42:09 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Pushes all the objects to Lua, in the same order as they were added.
|
|
|
|
*/
|
2011-10-13 18:25:50 +00:00
|
|
|
void pushObjects() const;
|
|
|
|
|
2011-10-13 18:42:09 +00:00
|
|
|
/**
|
|
|
|
* The struct wrapping the value and the type of the objects.
|
|
|
|
*/
|
2011-10-13 18:25:50 +00:00
|
|
|
struct Obj {
|
|
|
|
enum {
|
|
|
|
Nil,
|
|
|
|
Number,
|
|
|
|
Object,
|
|
|
|
String
|
|
|
|
} _type;
|
|
|
|
union {
|
|
|
|
float number;
|
|
|
|
const PoolObjectBase *object;
|
|
|
|
const char *string;
|
|
|
|
} _value;
|
|
|
|
};
|
|
|
|
Common::List<Obj> _objects;
|
2011-10-13 18:42:09 +00:00
|
|
|
|
|
|
|
friend class LuaBase;
|
2011-10-13 18:25:50 +00:00
|
|
|
};
|
|
|
|
|
2011-10-12 15:42:40 +00:00
|
|
|
class LuaBase {
|
|
|
|
public:
|
|
|
|
typedef LuaBase LuaClass;
|
2011-05-08 05:28:46 +00:00
|
|
|
|
2011-10-12 15:42:40 +00:00
|
|
|
LuaBase();
|
|
|
|
virtual ~LuaBase();
|
|
|
|
inline static LuaBase *instance() { return s_instance; }
|
|
|
|
|
2011-10-13 18:25:50 +00:00
|
|
|
int bundle_dofile(const char *filename);
|
|
|
|
int single_dofile(const char *filename);
|
|
|
|
|
2011-10-12 15:42:40 +00:00
|
|
|
virtual bool findCostume(lua_Object costumeObj, Actor *actor, Costume **costume);
|
|
|
|
virtual Common::String parseMsgText(const char *msg, char *msgId);
|
|
|
|
virtual void parseSayLineTable(lua_Object paramObj, bool *background, int *vol, int *pan, int *x, int *y);
|
|
|
|
virtual void setTextObjectParams(TextObjectCommon *textObject, lua_Object tableObj);
|
|
|
|
|
2011-10-13 18:25:50 +00:00
|
|
|
void update(int frameTime, int movieTime);
|
2011-10-12 15:42:40 +00:00
|
|
|
void setFrameTime(float frameTime);
|
|
|
|
void setMovieTime(float movieTime);
|
|
|
|
virtual void registerLua();
|
|
|
|
virtual void registerOpcodes();
|
|
|
|
virtual void boot();
|
2011-10-13 18:42:09 +00:00
|
|
|
virtual void postRestoreHandle() { }
|
2011-10-12 15:42:40 +00:00
|
|
|
|
2011-10-13 18:42:09 +00:00
|
|
|
/**
|
|
|
|
* Call a Lua function in the system table.
|
|
|
|
*
|
|
|
|
* @param name The name of the function.
|
|
|
|
*/
|
2011-10-13 18:25:50 +00:00
|
|
|
bool callback(const char *name);
|
2011-10-13 18:42:09 +00:00
|
|
|
/**
|
|
|
|
* Call a Lua function in the system table passing the specified arguments.
|
|
|
|
*
|
|
|
|
* @param name The name of the function;
|
|
|
|
* @param objects The arguments to be passed to the function.
|
|
|
|
*/
|
2011-10-13 18:25:50 +00:00
|
|
|
bool callback(const char *name, const LuaObjects &objects);
|
|
|
|
|
2011-10-13 18:42:09 +00:00
|
|
|
protected:
|
|
|
|
bool getbool(int num);
|
|
|
|
void pushbool(bool val);
|
|
|
|
void pushobject(const PoolObjectBase *o);
|
|
|
|
int getobject(lua_Object obj);
|
|
|
|
Actor *getactor(lua_Object obj);
|
|
|
|
TextObject *gettextobject(lua_Object obj);
|
|
|
|
Font *getfont(lua_Object obj);
|
|
|
|
PoolColor *getcolor(lua_Object obj);
|
|
|
|
PrimitiveObject *getprimitive(lua_Object obj);
|
|
|
|
ObjectState *getobjectstate(lua_Object obj);
|
2011-10-13 18:25:50 +00:00
|
|
|
|
2011-10-12 15:42:40 +00:00
|
|
|
DECLARE_LUA_OPCODE(dummyHandler);
|
|
|
|
DECLARE_LUA_OPCODE(typeOverride);
|
|
|
|
DECLARE_LUA_OPCODE(concatFallback);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// 0 - translate from '/msgId/'
|
|
|
|
// 1 - don't translate - message after '/msgId'
|
|
|
|
// 2 - return '/msgId/'
|
|
|
|
int _translationMode;
|
2011-10-13 18:25:50 +00:00
|
|
|
unsigned int _frameTimeCollection;
|
|
|
|
|
|
|
|
int refSystemTable;
|
|
|
|
int refTypeOverride;
|
|
|
|
int refOldConcatFallback;
|
|
|
|
int refTextObjectX;
|
|
|
|
int refTextObjectY;
|
|
|
|
int refTextObjectFont;
|
|
|
|
int refTextObjectWidth;
|
|
|
|
int refTextObjectHeight;
|
|
|
|
int refTextObjectFGColor;
|
|
|
|
int refTextObjectBGColor;
|
|
|
|
int refTextObjectFXColor;
|
|
|
|
int refTextObjectHIColor;
|
|
|
|
int refTextObjectDuration;
|
|
|
|
int refTextObjectCenter;
|
|
|
|
int refTextObjectLJustify;
|
|
|
|
int refTextObjectRJustify;
|
|
|
|
int refTextObjectVolume;
|
|
|
|
int refTextObjectBackground;
|
|
|
|
int refTextObjectPan;
|
2011-10-12 15:42:40 +00:00
|
|
|
|
|
|
|
static LuaBase *s_instance;
|
2011-10-13 18:42:09 +00:00
|
|
|
|
|
|
|
friend class LuaObjects;
|
2011-10-12 15:42:40 +00:00
|
|
|
};
|
2004-03-03 21:43:34 +00:00
|
|
|
|
2009-05-25 06:49:57 +00:00
|
|
|
} // end of namespace Grim
|
|
|
|
|
2003-08-15 18:00:22 +00:00
|
|
|
#endif
|