25 #include "lua/lualib.h" 27 #include "toluapp/tolua++.h" 70 warning(
"Lua instances were not freed properly");
96 const char *data =
reinterpret_cast<const char *
>(memStream->
getData());
97 const int dataSize = memStream->
size();
99 const int execResult = lua_dobuffer(
_luaState, data, dataSize, path.
c_str());
100 if (execResult != 0) {
110 if (execResult != 0) {
116 assert(!name.
empty());
119 std::vector<Common::UString> parts;
122 error(
"Lua call \"%s\" failed: bad name", name.
c_str());
134 for (
uint32 i = 1; i < parts.size(); ++i) {
150 return stack.getVariableAt(-1);
174 assert(!name.
empty());
198 assert(!name.
empty());
216 lua_CFunction deleter) {
218 assert(!name.
empty());
239 assert(!name.
empty());
246 assert(!name.
empty() && getter);
253 assert(!name.
empty() && func);
280 static const TableRef invalidInstance;
285 return invalidInstance;
287 return found->second;
358 "function mt_new_index(table, key, value)" 359 " local objClass = getmetatable(table).__objectClass" 360 " if objClass ~= nil then" 361 " local cppInstance = rawget(table, \"CPP_instance\")" 362 " if cppInstance[key] ~= nil then" 363 " cppInstance[key] = value" 367 " rawset(table, key, value)" 374 const char *message = luaL_checkstring(state, -1);
375 error(
"Lua has panicked: %s", message);
416 scriptMan->setLuaInstanceForObject(
object,
instance);
431 scriptMan->unsetLuaInstanceForObject(
object);
#define ResMan
Shortcut for accessing the sound manager.
TableRef getGlobalTable(const Common::UString &name) const
static int luaSetGCInterval(lua_State *state)
void beginRegisterClass(const Common::UString &name, const Common::UString &baseName="", lua_CFunction deleter=0)
Begin registration of a class.
#define TypeMan
Shortcut for accessing the file type manager.
TableRef getTableAt(int index) const
Return a table at the given index in the stack.
static int luaPlayFile(lua_State *state)
A class holding an UTF-8 string.
const TableRef & getLuaInstanceForObject(void *object) const
void unsetLuaInstanceForObject(void *object)
Common::UString getStringAt(int index) const
Return a string at the given index in the stack.
Variables call(const Variables ¶ms) const
TableRef getTableAt(int index) const
void closeLuaState()
Close the current Lua state.
A reference to a Lua function.
T * getUserTypeAt(int index, const Common::UString &type="") const
Return a usertype value at the given index in the stack.
void endRegisterNamespace()
End registration of the current namespace.
const FunctionRef & getFunction() const
int getSize() const
Return the number of elements in the stack.
void removeIgnoredFile(const Common::UString &path)
Remove a file from the ignore list.
static int atPanic(lua_State *state)
Handler of the Lua panic situations.
Utility functions to handle files used in BioWare's Aurora engine.
static int luaRegisterSubst(lua_State *state)
void pushUserType(T &value, const Common::UString &type)
Push a usertype value onto the stack.
void declareClass(const Common::UString &name)
Declare a class with the given name.
A simple scoped smart pointer template.
void executeDefaultCode()
void registerConstant(const Common::UString &name, float value)
Register a constant.
FunctionRef getFunctionAt(int index) const
static int luaRegisterHandler(lua_State *state)
Basic exceptions to throw.
void addIgnoredFile(const Common::UString &path)
Add a file to the ignore list.
const byte * getData() const
static int luaGetLua(lua_State *state)
Lua bindings.
const char * c_str() const
Return the (utf8 encoded) string data.
TableRef getMetaTable() const
void executeString(const Common::UString &code)
Execute a script string.
void endRegister()
End registration of the entities.
Utility templates and functions.
#define DECLARE_SINGLETON(T)
Note that you need to use this macro from the global namespace.
void registerVariable(const Common::UString &name, lua_CFunction getter, lua_CFunction setter=0)
Register a variable.
void * getRawUserTypeAt(int index, const Common::UString &type="") const
Return a raw usertype value at the given index in the stack.
Type getTypeAt(int index) const
void endRegisterClass()
End registration of the current class.
static int luaUnregisterSubst(lua_State *state)
bool empty() const
Is the string empty?
void beginRegisterNamespace(const Common::UString &name)
Begin registration of a namespace.
std::vector< Variable > Variables
ObjectLuaInstanceMap _objectLuaInstances
void warning(const char *s,...)
void setFunctionAt(int index, const FunctionRef &value)
A reference to a Lua function.
void init()
Initialize the script subsystem.
static ScriptManager & instance()
bool isIgnoredFile(const Common::UString &path) const
Is this file in the ignore list?
Variable getGlobalVariable(const Common::UString &name) const
void executeFile(const Common::UString &path)
Execute a script file.
int _regNestingLevel
The current nesting level of the registration process.
void deinit()
Deinitialize the script subsystem.
void requireDeclaredClass(const Common::UString &name) const
Check whether a class with the given name was declared.
void injectNewIndexMetaEventIntoTable(const TableRef &table)
void beginRegister()
Begin registration of the entities.
lua_State * _luaState
The Lua state.
void registerDefaultBindings()
std::set< Common::UString > _ignoredFiles
A list of files that the script subsystem ignores.
bool ready() const
Was the script subsystem successfully initialized?
A reference to a Lua table.
A reference to a Lua table.
size_t size() const
Obtains the total size of the stream, measured in bytes.
void split(iterator splitPoint, UString &left, UString &right, bool remove=false) const
#define LuaScriptMan
Shortcut for accessing the script engine.
FunctionRef getGlobalFunction(const Common::UString &name) const
void NORETURN_PRE error(const char *s,...)
int getUsedMemoryAmount() const
Return the amount of memory in use by Lua (in Kbytes).
Variables callFunction(const Common::UString &name, const Variables ¶ms)
Call a Lua function.
void registerFunction(const Common::UString &name, lua_CFunction func)
Register a function.
The global resource manager for Aurora resources.
void setLuaInstanceForObject(void *object, const TableRef &luaInstance)
void openLuaState()
Open and setup a new Lua state.