diff options
Diffstat (limited to 'engines/sword25/script')
-rw-r--r-- | engines/sword25/script/lua_extensions.cpp | 4 | ||||
-rw-r--r-- | engines/sword25/script/luabindhelper.cpp | 22 | ||||
-rw-r--r-- | engines/sword25/script/luabindhelper.h | 20 | ||||
-rw-r--r-- | engines/sword25/script/luacallback.cpp | 18 | ||||
-rw-r--r-- | engines/sword25/script/luacallback.h | 22 | ||||
-rw-r--r-- | engines/sword25/script/luascript.cpp | 34 | ||||
-rw-r--r-- | engines/sword25/script/luascript.h | 6 |
7 files changed, 66 insertions, 60 deletions
diff --git a/engines/sword25/script/lua_extensions.cpp b/engines/sword25/script/lua_extensions.cpp index 5fbc0ab3bd..a9abb9ea82 100644 --- a/engines/sword25/script/lua_extensions.cpp +++ b/engines/sword25/script/lua_extensions.cpp @@ -43,7 +43,7 @@ namespace Sword25 { -static int Warning(::lua_State *L) { +static int Warning(lua_State *L) { #ifdef DEBUG int __startStackDepth = lua_gettop(L); #endif @@ -73,7 +73,7 @@ static const luaL_reg GLOBAL_FUNCTIONS[] = { // ----------------------------------------------------------------------------- bool BS_LuaScriptEngine::RegisterStandardLibExtensions() { - ::lua_State *L = m_State; + lua_State *L = m_State; BS_ASSERT(m_State); if (!BS_LuaBindhelper::AddFunctionsToLib(L, "", GLOBAL_FUNCTIONS)) return false; diff --git a/engines/sword25/script/luabindhelper.cpp b/engines/sword25/script/luabindhelper.cpp index 06e97ad2e2..f2182a6b11 100644 --- a/engines/sword25/script/luabindhelper.cpp +++ b/engines/sword25/script/luabindhelper.cpp @@ -48,7 +48,7 @@ namespace { const char * METATABLES_TABLE_NAME = "__METATABLES"; const char * PERMANENTS_TABLE_NAME = "Permanents"; - bool RegisterPermanent(::lua_State *L, const Common::String &Name) { + bool RegisterPermanent(lua_State *L, const Common::String &Name) { // A C function has to be on the stack if (!lua_iscfunction(L, -1)) return false; @@ -93,7 +93,7 @@ namespace Sword25 { * The array must be terminated with the enry (0, 0) * @return Returns true if successful, otherwise false. */ -bool BS_LuaBindhelper::AddFunctionsToLib(::lua_State *L, const Common::String &LibName, const luaL_reg *Functions) { +bool BS_LuaBindhelper::AddFunctionsToLib(lua_State *L, const Common::String &LibName, const luaL_reg *Functions) { #ifdef DEBUG int __startStackDepth = lua_gettop(L); #endif @@ -151,7 +151,7 @@ bool BS_LuaBindhelper::AddFunctionsToLib(::lua_State *L, const Common::String &L * The array must be terminated with the enry (0, 0) * @return Returns true if successful, otherwise false. */ -bool BS_LuaBindhelper::AddConstantsToLib(::lua_State *L, const Common::String &LibName, const lua_constant_reg *Constants) { +bool BS_LuaBindhelper::AddConstantsToLib(lua_State *L, const Common::String &LibName, const lua_constant_reg *Constants) { #ifdef DEBUG int __startStackDepth = lua_gettop(L); #endif @@ -198,7 +198,7 @@ bool BS_LuaBindhelper::AddConstantsToLib(::lua_State *L, const Common::String &L * The array must be terminated with the enry (0, 0) * @return Returns true if successful, otherwise false. */ -bool BS_LuaBindhelper::AddMethodsToClass(::lua_State *L, const Common::String &ClassName, const luaL_reg *Methods) { +bool BS_LuaBindhelper::AddMethodsToClass(lua_State *L, const Common::String &ClassName, const luaL_reg *Methods) { #ifdef DEBUG int __startStackDepth = lua_gettop(L); #endif @@ -238,7 +238,7 @@ bool BS_LuaBindhelper::AddMethodsToClass(::lua_State *L, const Common::String &C * @param GCHandler A function pointer * @return Returns true if successful, otherwise false. */ -bool BS_LuaBindhelper::SetClassGCHandler(::lua_State *L, const Common::String &ClassName, lua_CFunction GCHandler) { +bool BS_LuaBindhelper::SetClassGCHandler(lua_State *L, const Common::String &ClassName, lua_CFunction GCHandler) { #ifdef DEBUG int __startStackDepth = lua_gettop(L); #endif @@ -271,7 +271,7 @@ bool BS_LuaBindhelper::SetClassGCHandler(::lua_State *L, const Common::String &C // ----------------------------------------------------------------------------- namespace { - void PushMetatableTable(::lua_State *L) { + void PushMetatableTable(lua_State *L) { // Push the Metatable table onto the stack lua_getglobal(L, METATABLES_TABLE_NAME); @@ -290,7 +290,7 @@ namespace { namespace Sword25 { -bool BS_LuaBindhelper::GetMetatable(::lua_State *L, const Common::String &TableName) { +bool BS_LuaBindhelper::GetMetatable(lua_State *L, const Common::String &TableName) { // Push the Metatable table onto the stack PushMetatableTable(L); @@ -324,7 +324,7 @@ bool BS_LuaBindhelper::GetMetatable(::lua_State *L, const Common::String &TableN // ----------------------------------------------------------------------------- -bool BS_LuaBindhelper::_CreateTable(::lua_State *L, const Common::String &TableName) { +bool BS_LuaBindhelper::_CreateTable(lua_State *L, const Common::String &TableName) { const char *PartBegin = TableName.c_str(); while (PartBegin) { @@ -373,7 +373,7 @@ bool BS_LuaBindhelper::_CreateTable(::lua_State *L, const Common::String &TableN } // End of namespace Sword25 namespace { - Common::String GetLuaValueInfo(::lua_State *L, int StackIndex) { + Common::String GetLuaValueInfo(lua_State *L, int StackIndex) { switch (lua_type(L, StackIndex)) { case LUA_TNUMBER: lua_pushstring(L, lua_tostring(L, StackIndex)); @@ -405,7 +405,7 @@ namespace { namespace Sword25 { -Common::String BS_LuaBindhelper::StackDump(::lua_State *L) { +Common::String BS_LuaBindhelper::StackDump(lua_State *L) { Common::String oss; int i = lua_gettop(L); @@ -421,7 +421,7 @@ Common::String BS_LuaBindhelper::StackDump(::lua_State *L) { return oss; } -Common::String BS_LuaBindhelper::TableDump(::lua_State *L) { +Common::String BS_LuaBindhelper::TableDump(lua_State *L) { Common::String oss; oss += "------------------- Table Dump -------------------\n"; diff --git a/engines/sword25/script/luabindhelper.h b/engines/sword25/script/luabindhelper.h index ecc52fd417..6bb1a254b9 100644 --- a/engines/sword25/script/luabindhelper.h +++ b/engines/sword25/script/luabindhelper.h @@ -37,7 +37,7 @@ #include "sword25/kernel/common.h" -namespace { +namespace Lua { extern "C" { @@ -47,6 +47,8 @@ extern "C" } +using namespace Lua; + namespace Sword25 { #define lua_pushbooleancpp(L, b) (lua_pushboolean(L, b ? 1 : 0)) @@ -68,7 +70,7 @@ public: * The array must be terminated with the enry (0, 0) * @return Returns true if successful, otherwise false. */ - static bool AddFunctionsToLib(::lua_State *L, const Common::String &LibName, const luaL_reg *Functions); + static bool AddFunctionsToLib(lua_State *L, const Common::String &LibName, const luaL_reg *Functions); /** * Adds a set of constants to the Lua library @@ -79,7 +81,7 @@ public: * The array must be terminated with the enry (0, 0) * @return Returns true if successful, otherwise false. */ - static bool AddConstantsToLib(::lua_State * L, const Common::String & LibName, const lua_constant_reg * Constants); + static bool AddConstantsToLib(lua_State * L, const Common::String & LibName, const lua_constant_reg * Constants); /** * Adds a set of methods to a Lua class @@ -90,7 +92,7 @@ public: * The array must be terminated with the enry (0, 0) * @return Returns true if successful, otherwise false. */ - static bool AddMethodsToClass(::lua_State *L, const Common::String &ClassName, const luaL_reg *Methods); + static bool AddMethodsToClass(lua_State *L, const Common::String &ClassName, const luaL_reg *Methods); /** * Sets the garbage collector callback method when items of a particular class are deleted @@ -100,25 +102,25 @@ public: * @param GCHandler A function pointer * @return Returns true if successful, otherwise false. */ - static bool SetClassGCHandler(::lua_State *L, const Common::String &ClassName, lua_CFunction GCHandler); + static bool SetClassGCHandler(lua_State *L, const Common::String &ClassName, lua_CFunction GCHandler); /** * Returns a string containing a stack dump of the Lua stack * @param L A pointer to the Lua VM */ - static Common::String StackDump(::lua_State *L); + static Common::String StackDump(lua_State *L); /** * Returns a string that describes the contents of a table * @param L A pointer to the Lua VM * @remark The table must be on the Lua stack to be read out. */ - static Common::String TableDump(::lua_State *L); + static Common::String TableDump(lua_State *L); - static bool GetMetatable(::lua_State *L, const Common::String &TableName); + static bool GetMetatable(lua_State *L, const Common::String &TableName); private: - static bool _CreateTable(::lua_State *L, const Common::String &TableName); + static bool _CreateTable(lua_State *L, const Common::String &TableName); }; } // End of namespace Sword25 diff --git a/engines/sword25/script/luacallback.cpp b/engines/sword25/script/luacallback.cpp index 7fbbc1457a..37c6d04596 100644 --- a/engines/sword25/script/luacallback.cpp +++ b/engines/sword25/script/luacallback.cpp @@ -39,7 +39,7 @@ #include "sword25/script/luacallback.h" #include "sword25/script/luabindhelper.h" -namespace { +namespace Lua { extern "C" { @@ -59,7 +59,7 @@ namespace Sword25 { // ----------------------------------------------------------------------------- -BS_LuaCallback::BS_LuaCallback(::lua_State *L) { +BS_LuaCallback::BS_LuaCallback(lua_State *L) { // Create callback table lua_newtable(L); lua_setglobal(L, CALLBACKTABLE_NAME); @@ -72,7 +72,7 @@ BS_LuaCallback::~BS_LuaCallback() { // ----------------------------------------------------------------------------- -void BS_LuaCallback::RegisterCallbackFunction(::lua_State *L, unsigned int ObjectHandle) { +void BS_LuaCallback::RegisterCallbackFunction(lua_State *L, unsigned int ObjectHandle) { BS_ASSERT(lua_isfunction(L, -1)); EnsureObjectCallbackTableExists(L, ObjectHandle); @@ -86,7 +86,7 @@ void BS_LuaCallback::RegisterCallbackFunction(::lua_State *L, unsigned int Objec // ----------------------------------------------------------------------------- -void BS_LuaCallback::UnregisterCallbackFunction(::lua_State *L, unsigned int ObjectHandle) { +void BS_LuaCallback::UnregisterCallbackFunction(lua_State *L, unsigned int ObjectHandle) { BS_ASSERT(lua_isfunction(L, -1)); EnsureObjectCallbackTableExists(L,ObjectHandle); @@ -116,7 +116,7 @@ void BS_LuaCallback::UnregisterCallbackFunction(::lua_State *L, unsigned int Obj // ----------------------------------------------------------------------------- -void BS_LuaCallback::RemoveAllObjectCallbacks(::lua_State *L, unsigned int ObjectHandle) { +void BS_LuaCallback::RemoveAllObjectCallbacks(lua_State *L, unsigned int ObjectHandle) { PushCallbackTable(L); // Remove the object callback from the callback table @@ -129,7 +129,7 @@ void BS_LuaCallback::RemoveAllObjectCallbacks(::lua_State *L, unsigned int Objec // ----------------------------------------------------------------------------- -void BS_LuaCallback::InvokeCallbackFunctions(::lua_State *L, unsigned int ObjectHandle) { +void BS_LuaCallback::InvokeCallbackFunctions(lua_State *L, unsigned int ObjectHandle) { EnsureObjectCallbackTableExists(L, ObjectHandle); // Iterate through the table and perform all the callbacks @@ -164,7 +164,7 @@ void BS_LuaCallback::InvokeCallbackFunctions(::lua_State *L, unsigned int Object // ----------------------------------------------------------------------------- -void BS_LuaCallback::EnsureObjectCallbackTableExists(::lua_State *L, unsigned int ObjectHandle) { +void BS_LuaCallback::EnsureObjectCallbackTableExists(lua_State *L, unsigned int ObjectHandle) { PushObjectCallbackTable(L, ObjectHandle); // If the table is nil, it must first be created @@ -187,13 +187,13 @@ void BS_LuaCallback::EnsureObjectCallbackTableExists(::lua_State *L, unsigned in // ----------------------------------------------------------------------------- -void BS_LuaCallback::PushCallbackTable(::lua_State *L) { +void BS_LuaCallback::PushCallbackTable(lua_State *L) { lua_getglobal(L, CALLBACKTABLE_NAME); } // ----------------------------------------------------------------------------- -void BS_LuaCallback::PushObjectCallbackTable(::lua_State *L, unsigned int ObjectHandle) { +void BS_LuaCallback::PushObjectCallbackTable(lua_State *L, unsigned int ObjectHandle) { PushCallbackTable(L); // Push Object Callback table onto the stack diff --git a/engines/sword25/script/luacallback.h b/engines/sword25/script/luacallback.h index 6a5b43be8a..7b7bbbe024 100644 --- a/engines/sword25/script/luacallback.h +++ b/engines/sword25/script/luacallback.h @@ -45,12 +45,14 @@ // Forward Declarations // ----------------------------------------------------------------------------- -namespace { +namespace Lua { struct lua_State; } +using namespace Lua; + namespace Sword25 { // ----------------------------------------------------------------------------- @@ -59,26 +61,26 @@ namespace Sword25 { class BS_LuaCallback { public: - BS_LuaCallback(::lua_State * L); + BS_LuaCallback(lua_State * L); virtual ~BS_LuaCallback(); // Funktion muss auf dem Lua-Stack liegen. - void RegisterCallbackFunction(::lua_State *L, unsigned int ObjectHandle); + void RegisterCallbackFunction(lua_State *L, unsigned int ObjectHandle); // Funktion muss auf dem Lua-Stack liegen. - void UnregisterCallbackFunction(::lua_State *L, unsigned int ObjectHandle); + void UnregisterCallbackFunction(lua_State *L, unsigned int ObjectHandle); - void RemoveAllObjectCallbacks(::lua_State *L, unsigned int ObjectHandle); + void RemoveAllObjectCallbacks(lua_State *L, unsigned int ObjectHandle); - void InvokeCallbackFunctions(::lua_State *L, unsigned int ObjectHandle); + void InvokeCallbackFunctions(lua_State *L, unsigned int ObjectHandle); protected: - virtual int PreFunctionInvokation(::lua_State *L) { return 0; } + virtual int PreFunctionInvokation(lua_State *L) { return 0; } private: - void EnsureObjectCallbackTableExists(::lua_State *L,unsigned int ObjectHandle); - void PushCallbackTable(::lua_State *L); - void PushObjectCallbackTable(::lua_State *L, unsigned int ObjectHandle); + void EnsureObjectCallbackTableExists(lua_State *L,unsigned int ObjectHandle); + void PushCallbackTable(lua_State *L); + void PushObjectCallbackTable(lua_State *L, unsigned int ObjectHandle); }; } // End of namespace Sword25 diff --git a/engines/sword25/script/luascript.cpp b/engines/sword25/script/luascript.cpp index 8af0128c72..129dd03c8a 100644 --- a/engines/sword25/script/luascript.cpp +++ b/engines/sword25/script/luascript.cpp @@ -38,28 +38,28 @@ // Includes // ----------------------------------------------------------------------------- -//namespace { +#include "sword25/package/packagemanager.h" +#include "sword25/script/luascript.h" +#include "sword25/script/luabindhelper.h" + +#include "sword25/kernel/outputpersistenceblock.h" +#include "sword25/kernel/inputpersistenceblock.h" -extern "C" -{ +namespace Lua { + +extern "C" { #include "sword25/util/lua/lua.h" #include "sword25/util/lua/lualib.h" #include "sword25/util/lua/lauxlib.h" #include "sword25/util/pluto/pluto.h" } -//} - -#include "sword25/package/packagemanager.h" -#include "sword25/script/luascript.h" -#include "sword25/script/luabindhelper.h" - -#include "sword25/kernel/outputpersistenceblock.h" -#include "sword25/kernel/inputpersistenceblock.h" +} namespace Sword25 { using namespace std; +using namespace Lua; // ----------------------------------------------------------------------------- // Constructor / Destructor @@ -85,7 +85,7 @@ BS_Service *BS_LuaScriptEngine_CreateObject(BS_Kernel * KernelPtr) { return new // ----------------------------------------------------------------------------- namespace { - int PanicCB(::lua_State *L) { + int PanicCB(lua_State *L) { BS_LOG_ERRORLN("Lua panic. Error message: %s", lua_isnil(L, -1) ? "" : lua_tostring(L, -1)); return 0; } @@ -193,7 +193,7 @@ bool BS_LuaScriptEngine::ExecuteString(const Common::String &Code) { namespace { - void RemoveForbiddenFunctions(::lua_State *L) { + void RemoveForbiddenFunctions(lua_State *L) { static const char *FORBIDDEN_FUNCTIONS[] = { "dofile", 0 @@ -326,7 +326,7 @@ namespace { // ------------------------------------------------------------------------- - bool PushPermanentsTable(::lua_State *L, PERMANENT_TABLE_TYPE TableType) { + bool PushPermanentsTable(lua_State *L, PERMANENT_TABLE_TYPE TableType) { // Permanents-Table lua_newtable(L); @@ -409,7 +409,7 @@ namespace { // ----------------------------------------------------------------------------- namespace { - int Chunkwriter(::lua_State *L, const void *p, size_t sz, void *ud) { + int Chunkwriter(lua_State *L, const void *p, size_t sz, void *ud) { vector<unsigned char> & chunkData = *reinterpret_cast<vector<unsigned char> * >(ud); const unsigned char *buffer = reinterpret_cast<const unsigned char *>(p); @@ -457,7 +457,7 @@ namespace { // ------------------------------------------------------------------------ - const char *Chunkreader(::lua_State *L, void *ud, size_t *sz) { + const char *Chunkreader(lua_State *L, void *ud, size_t *sz) { ChunkreaderData & cd = *reinterpret_cast<ChunkreaderData *>(ud); if (!cd.BufferReturned) { @@ -471,7 +471,7 @@ namespace { // ------------------------------------------------------------------------- - void ClearGlobalTable(::lua_State *L, const char **Exceptions) { + void ClearGlobalTable(lua_State *L, const char **Exceptions) { // Iterate over all elements of the global table lua_pushvalue(L, LUA_GLOBALSINDEX); lua_pushnil(L); diff --git a/engines/sword25/script/luascript.h b/engines/sword25/script/luascript.h index 4d216be413..f0a8a9bbdc 100644 --- a/engines/sword25/script/luascript.h +++ b/engines/sword25/script/luascript.h @@ -48,12 +48,14 @@ // Forward declarations // ----------------------------------------------------------------------------- -namespace { +namespace Lua { struct lua_State; } +using namespace Lua; + namespace Sword25 { class BS_Kernel; @@ -115,7 +117,7 @@ public: virtual bool Unpersist(BS_InputPersistenceBlock &Reader); private: - ::lua_State *m_State; + lua_State *m_State; int m_PcallErrorhandlerRegistryIndex; bool RegisterStandardLibs(); |