You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.7 KiB

13 years ago
#ifndef SCRIPTCONTEXT_H
#define SCRIPTCONTEXT_H
13 years ago
#include <global.h>
13 years ago
#include "scriptobject.h"
13 years ago
#define reportFuncError(a) reportError(a, __FUNCTION__)
#define reportFuncErrorWithTraceback(a) reportErrorWithTraceback(a, __FUNCTION__)
13 years ago
struct lua_State;
13 years ago
class ScriptContext
13 years ago
{
public:
13 years ago
ScriptContext() : L(NULL) { }
void init();
void terminate();
13 years ago
void loadAllModules();
13 years ago
bool loadFile(const std::string& fileName);
bool loadBuffer(const std::string& text, const std::string& what = "luaBuffer");
13 years ago
bool loadBufferAsFunction(const std::string& text, const std::string& what = "luaBuffer");
void reportError(const std::string& errorDesc, const char *funcName = NULL);
void reportErrorWithTraceback(const std::string& errorDesc, const char *funcName = NULL);
13 years ago
void collectGarbage();
13 years ago
13 years ago
int getStackSize();
void insert(int index);
void swap(int index);
13 years ago
void remove(int index);
bool next(int index = -2);
13 years ago
void releaseRef(int ref);
void newTable();
void setTable(int index = -3);
void *newUserdata(int size);
void newMetatable(const std::string& name);
void setMetatable(const std::string& name, int index = -1);
void rawGet(const std::string& key);
void rawSet(const std::string& key);
void getField(const std::string& key);
void setField(const std::string& key);
13 years ago
void getScriptObjectField(const ScriptObjectPtr& scriptobject, const std::string& field);
void setScriptObjectField(const ScriptObjectPtr& scriptobject, const std::string& field);
13 years ago
void rawGetGlobalTableField(const std::string& globalTable, const std::string& key);
void rawSetGlobalTableField(const std::string& globalTable, const std::string& key);
void getGlobal(const std::string& key);
void setGlobal(const std::string& key);
bool isNil(int index = -1);
bool isBoolean(int index = -1);
bool isNumber(int index = -1);
bool isString(int index = -1);
bool isTable(int index = -1);
bool isUserdata(int index = -1);
bool isFunction(int index = -1);
bool isCFunction(int index = -1);
bool isLuaFunction(int index = -1);
void pop(int n = 1);
bool popBoolean();
int popInteger();
std::string popString();
13 years ago
ScriptObjectPtr popClassInstance();
13 years ago
int popRef();
13 years ago
void pushNil();
void pushBoolean(bool b);
void pushInteger(int i);
void pushString(const std::string& str);
13 years ago
void pushClassInstance(const ScriptObjectPtr& object);
void pushValue(int index = -1);
13 years ago
void pushRef(int ref);
13 years ago
std::string getFunctionSourcePath(bool functionIsOnStack, int level = 1);
bool callFunction(int numArgs = 0, int numRets = 0);
13 years ago
void callModuleField(const std::string& module, const std::string& field);
13 years ago
typedef int (*LuaCFunction)();
13 years ago
void setupPackageLoader();
void registerClass(const std::string& klass, const std::string& baseClass = "");
13 years ago
void registerMemberField(const std::string& field, LuaCFunction getFunction, LuaCFunction setFunction = NULL);
void registerMemberFunction(const std::string& functionName, LuaCFunction function);
13 years ago
void registerGlobalFunction(const std::string& functionName, LuaCFunction function);
void registerModule(const std::string& module);
13 years ago
static int luaPackageLoader(lua_State* L);
static int luaIndexMetaMethod(lua_State* L);
static int luaNewIndexMetaMethod(lua_State* L);
static int luaEqualMetaMethod(lua_State* L);
static int luaGarbageCollectMetaMethod(lua_State* L);
static int luaFunctionCallback(lua_State* L);
static int luaErrorHandler(lua_State *L);
13 years ago
private:
std::vector<LuaCFunction> m_functions;
13 years ago
std::string m_currentClass;
13 years ago
lua_State *L;
};
13 years ago
extern ScriptContext g_lua;
13 years ago
13 years ago
#endif // SCRIPTCONTEXT_H