aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/script/luabindhelper.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2010-10-03 13:25:22 +0000
committerEugene Sandulenko2010-10-13 00:08:28 +0000
commit54ccc8f4c906cd4f84c955581c0368886a7a9c78 (patch)
tree04b7ce0ef984565e4824ad4b73dc32493e65f018 /engines/sword25/script/luabindhelper.cpp
parent1e15d8efb73503d9f613cc60023771b0c11f0dd6 (diff)
downloadscummvm-rg350-54ccc8f4c906cd4f84c955581c0368886a7a9c78.tar.gz
scummvm-rg350-54ccc8f4c906cd4f84c955581c0368886a7a9c78.tar.bz2
scummvm-rg350-54ccc8f4c906cd4f84c955581c0368886a7a9c78.zip
SWORD25: Enforced code naming conventions in script/*
svn-id: r53391
Diffstat (limited to 'engines/sword25/script/luabindhelper.cpp')
-rw-r--r--engines/sword25/script/luabindhelper.cpp151
1 files changed, 67 insertions, 84 deletions
diff --git a/engines/sword25/script/luabindhelper.cpp b/engines/sword25/script/luabindhelper.cpp
index 843e8dd4de..5367854218 100644
--- a/engines/sword25/script/luabindhelper.cpp
+++ b/engines/sword25/script/luabindhelper.cpp
@@ -32,25 +32,20 @@
*
*/
-// -----------------------------------------------------------------------------
-// Includes
-// -----------------------------------------------------------------------------
-
#include "sword25/kernel/kernel.h"
#include "sword25/script/luabindhelper.h"
#include "sword25/script/luascript.h"
#define BS_LOG_PREFIX "LUABINDHELPER"
-// -----------------------------------------------------------------------------
-
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;
+ if (!lua_iscfunction(L, -1))
+ return false;
// Make sure that the Permanents-Table is on top of the stack
lua_getfield(L, LUA_REGISTRYINDEX, PERMANENTS_TABLE_NAME);
@@ -71,7 +66,7 @@ bool RegisterPermanent(lua_State *L, const Common::String &Name) {
// C function with the name of an index in the Permanents-Table
lua_insert(L, -2);
- lua_setfield(L, -2, Name.c_str());
+ lua_setfield(L, -2, name.c_str());
// Remove the Permanents-Table from the stack
lua_pop(L, 1);
@@ -82,8 +77,6 @@ bool RegisterPermanent(lua_State *L, const Common::String &Name) {
namespace Sword25 {
-// -----------------------------------------------------------------------------
-
/**
* Registers a set of functions into a Lua library.
* @param L A pointer to the Lua VM
@@ -93,38 +86,38 @@ namespace Sword25 {
* The array must be terminated with the enry (0, 0)
* @return Returns true if successful, otherwise false.
*/
-bool LuaBindhelper::AddFunctionsToLib(lua_State *L, const Common::String &LibName, const luaL_reg *Functions) {
+bool LuaBindhelper::addFunctionsToLib(lua_State *L, const Common::String &libName, const luaL_reg *functions) {
#ifdef DEBUG
int __startStackDepth = lua_gettop(L);
#endif
// If the table name is empty, the functions are to be added to the global namespace
- if (LibName.size() == 0) {
- for (; Functions->name; ++Functions) {
- lua_pushstring(L, Functions->name);
- lua_pushcclosure(L, Functions->func, 0);
+ if (libName.size() == 0) {
+ for (; functions->name; ++functions) {
+ lua_pushstring(L, functions->name);
+ lua_pushcclosure(L, functions->func, 0);
lua_settable(L, LUA_GLOBALSINDEX);
// Function is being permanently registed, so persistence can be ignored
- lua_pushstring(L, Functions->name);
+ lua_pushstring(L, functions->name);
lua_gettable(L, LUA_GLOBALSINDEX);
- RegisterPermanent(L, Functions->name);
+ registerPermanent(L, functions->name);
}
} else { // If the table name is not empty, the functions are added to the given table
// Ensure that the library table exists
- if (!_CreateTable(L, LibName)) return false;
+ if (!createTable(L, libName)) return false;
// Register each function into the table
- for (; Functions->name; ++Functions) {
+ for (; functions->name; ++functions) {
// Function registration
- lua_pushstring(L, Functions->name);
- lua_pushcclosure(L, Functions->func, 0);
+ lua_pushstring(L, functions->name);
+ lua_pushcclosure(L, functions->func, 0);
lua_settable(L, -3);
// Function is being permanently registed, so persistence can be ignored
- lua_pushstring(L, Functions->name);
+ lua_pushstring(L, functions->name);
lua_gettable(L, -2);
- RegisterPermanent(L, LibName + "." + Functions->name);
+ registerPermanent(L, libName + "." + functions->name);
}
// Remove the library table from the Lua stack
@@ -138,8 +131,6 @@ bool LuaBindhelper::AddFunctionsToLib(lua_State *L, const Common::String &LibNam
return true;
}
-// -----------------------------------------------------------------------------
-
/**
* Adds a set of constants to the Lua library
* @param L A pointer to the Lua VM
@@ -149,28 +140,28 @@ bool LuaBindhelper::AddFunctionsToLib(lua_State *L, const Common::String &LibNam
* The array must be terminated with the enry (0, 0)
* @return Returns true if successful, otherwise false.
*/
-bool LuaBindhelper::AddConstantsToLib(lua_State *L, const Common::String &LibName, const lua_constant_reg *Constants) {
+bool LuaBindhelper::addConstantsToLib(lua_State *L, const Common::String &libName, const lua_constant_reg *constants) {
#ifdef DEBUG
int __startStackDepth = lua_gettop(L);
#endif
// If the table is empty, the constants are added to the global namespace
- if (LibName.size() == 0) {
- for (; Constants->Name; ++Constants) {
- lua_pushstring(L, Constants->Name);
- lua_pushnumber(L, Constants->Value);
+ if (libName.size() == 0) {
+ for (; constants->Name; ++constants) {
+ lua_pushstring(L, constants->Name);
+ lua_pushnumber(L, constants->Value);
lua_settable(L, LUA_GLOBALSINDEX);
}
}
// If the table name is nto empty, the constants are added to that table
else {
// Ensure that the library table exists
- if (!_CreateTable(L, LibName)) return false;
+ if (!createTable(L, libName)) return false;
// Register each constant in the table
- for (; Constants->Name; ++Constants) {
- lua_pushstring(L, Constants->Name);
- lua_pushnumber(L, Constants->Value);
+ for (; constants->Name; ++constants) {
+ lua_pushstring(L, constants->Name);
+ lua_pushnumber(L, constants->Value);
lua_settable(L, -3);
}
@@ -185,8 +176,6 @@ bool LuaBindhelper::AddConstantsToLib(lua_State *L, const Common::String &LibNam
return true;
}
-// -----------------------------------------------------------------------------
-
/**
* Adds a set of methods to a Lua class
* @param L A pointer to the Lua VM
@@ -196,24 +185,24 @@ bool LuaBindhelper::AddConstantsToLib(lua_State *L, const Common::String &LibNam
* The array must be terminated with the enry (0, 0)
* @return Returns true if successful, otherwise false.
*/
-bool LuaBindhelper::AddMethodsToClass(lua_State *L, const Common::String &ClassName, const luaL_reg *Methods) {
+bool LuaBindhelper::addMethodsToClass(lua_State *L, const Common::String &className, const luaL_reg *methods) {
#ifdef DEBUG
int __startStackDepth = lua_gettop(L);
#endif
// Load the metatable onto the Lua stack
- if (!GetMetatable(L, ClassName)) return false;
+ if (!getMetatable(L, className)) return false;
// Register each method in the Metatable
- for (; Methods->name; ++Methods) {
- lua_pushstring(L, Methods->name);
- lua_pushcclosure(L, Methods->func, 0);
+ for (; methods->name; ++methods) {
+ lua_pushstring(L, methods->name);
+ lua_pushcclosure(L, methods->func, 0);
lua_settable(L, -3);
// Function is being permanently registed, so persistence can be ignored
- lua_pushstring(L, Methods->name);
+ lua_pushstring(L, methods->name);
lua_gettable(L, -2);
- RegisterPermanent(L, ClassName + "." + Methods->name);
+ registerPermanent(L, className + "." + methods->name);
}
// Remove the metatable from the stack
@@ -226,8 +215,6 @@ bool LuaBindhelper::AddMethodsToClass(lua_State *L, const Common::String &ClassN
return true;
}
-// -----------------------------------------------------------------------------
-
/**
* Sets the garbage collector callback method when items of a particular class are deleted
* @param L A pointer to the Lua VM
@@ -236,13 +223,13 @@ bool LuaBindhelper::AddMethodsToClass(lua_State *L, const Common::String &ClassN
* @param GCHandler A function pointer
* @return Returns true if successful, otherwise false.
*/
-bool LuaBindhelper::SetClassGCHandler(lua_State *L, const Common::String &ClassName, lua_CFunction GCHandler) {
+bool LuaBindhelper::setClassGCHandler(lua_State *L, const Common::String &className, lua_CFunction GCHandler) {
#ifdef DEBUG
int __startStackDepth = lua_gettop(L);
#endif
// Load the metatable onto the Lua stack
- if (!GetMetatable(L, ClassName)) return false;
+ if (!getMetatable(L, className)) return false;
// Add the GC handler to the Metatable
lua_pushstring(L, "__gc");
@@ -252,7 +239,7 @@ bool LuaBindhelper::SetClassGCHandler(lua_State *L, const Common::String &ClassN
// Function is being permanently registed, so persistence can be ignored
lua_pushstring(L, "__gc");
lua_gettable(L, -2);
- RegisterPermanent(L, ClassName + ".__gc");
+ registerPermanent(L, className + ".__gc");
// Remove the metatable from the stack
lua_pop(L, 1);
@@ -266,10 +253,8 @@ bool LuaBindhelper::SetClassGCHandler(lua_State *L, const Common::String &ClassN
} // End of namespace Sword25
-// -----------------------------------------------------------------------------
-
namespace {
-void PushMetatableTable(lua_State *L) {
+void pushMetatableTable(lua_State *L) {
// Push the Metatable table onto the stack
lua_getglobal(L, METATABLES_TABLE_NAME);
@@ -288,12 +273,12 @@ void PushMetatableTable(lua_State *L) {
namespace Sword25 {
-bool LuaBindhelper::GetMetatable(lua_State *L, const Common::String &TableName) {
+bool LuaBindhelper::getMetatable(lua_State *L, const Common::String &tableName) {
// Push the Metatable table onto the stack
- PushMetatableTable(L);
+ pushMetatableTable(L);
// Versuchen, die gewünschte Metatabelle auf den Stack zu legen. Wenn sie noch nicht existiert, muss sie erstellt werden.
- lua_getfield(L, -1, TableName.c_str());
+ lua_getfield(L, -1, tableName.c_str());
if (lua_isnil(L, -1)) {
// Pop nil from stack
lua_pop(L, 1);
@@ -311,7 +296,7 @@ bool LuaBindhelper::GetMetatable(lua_State *L, const Common::String &TableName)
// Set the table name and push it onto the stack
lua_pushvalue(L, -1);
- lua_setfield(L, -3, TableName.c_str());
+ lua_setfield(L, -3, tableName.c_str());
}
// Remove the Metatable table from the stack
@@ -320,29 +305,27 @@ bool LuaBindhelper::GetMetatable(lua_State *L, const Common::String &TableName)
return true;
}
-// -----------------------------------------------------------------------------
-
-bool LuaBindhelper::_CreateTable(lua_State *L, const Common::String &TableName) {
- const char *PartBegin = TableName.c_str();
+bool LuaBindhelper::createTable(lua_State *L, const Common::String &tableName) {
+ const char *partBegin = tableName.c_str();
- while (PartBegin - TableName.c_str() < (int)TableName.size()) {
- const char *PartEnd = strchr(PartBegin, '.');
- if (!PartEnd)
- PartEnd = PartBegin + strlen(PartBegin);
- Common::String SubTableName(PartBegin, PartEnd);
+ while (partBegin - tableName.c_str() < (int)tableName.size()) {
+ const char *partEnd = strchr(partBegin, '.');
+ if (!partEnd)
+ partEnd = partBegin + strlen(partBegin);
+ Common::String subTableName(partBegin, partEnd);
// Tables with an empty string as the name are not allowed
- if (SubTableName.size() == 0)
+ if (subTableName.size() == 0)
return false;
// Verify that the table with the name already exists
// The first round will be searched in the global namespace, with later passages
// in the corresponding parent table in the stack
- if (PartBegin == TableName.c_str()) {
- lua_pushstring(L, SubTableName.c_str());
+ if (partBegin == tableName.c_str()) {
+ lua_pushstring(L, subTableName.c_str());
lua_gettable(L, LUA_GLOBALSINDEX);
} else {
- lua_pushstring(L, SubTableName.c_str());
+ lua_pushstring(L, subTableName.c_str());
lua_gettable(L, -2);
if (!lua_isnil(L, -1))
lua_remove(L, -2);
@@ -355,9 +338,9 @@ bool LuaBindhelper::_CreateTable(lua_State *L, const Common::String &TableName)
// Create new table
lua_newtable(L);
- lua_pushstring(L, SubTableName.c_str());
+ lua_pushstring(L, subTableName.c_str());
lua_pushvalue(L, -2);
- if (PartBegin == TableName.c_str())
+ if (partBegin == tableName.c_str())
lua_settable(L, LUA_GLOBALSINDEX);
else {
lua_settable(L, -4);
@@ -365,7 +348,7 @@ bool LuaBindhelper::_CreateTable(lua_State *L, const Common::String &TableName)
}
}
- PartBegin = PartEnd + 1;
+ partBegin = partEnd + 1;
}
return true;
@@ -374,18 +357,18 @@ bool LuaBindhelper::_CreateTable(lua_State *L, const Common::String &TableName)
} // End of namespace Sword25
namespace {
-Common::String GetLuaValueInfo(lua_State *L, int StackIndex) {
- switch (lua_type(L, StackIndex)) {
+Common::String getLuaValueInfo(lua_State *L, int stackIndex) {
+ switch (lua_type(L, stackIndex)) {
case LUA_TNUMBER:
- lua_pushstring(L, lua_tostring(L, StackIndex));
+ lua_pushstring(L, lua_tostring(L, stackIndex));
break;
case LUA_TSTRING:
- lua_pushfstring(L, "\"%s\"", lua_tostring(L, StackIndex));
+ lua_pushfstring(L, "\"%s\"", lua_tostring(L, stackIndex));
break;
case LUA_TBOOLEAN:
- lua_pushstring(L, (lua_toboolean(L, StackIndex) ? "true" : "false"));
+ lua_pushstring(L, (lua_toboolean(L, stackIndex) ? "true" : "false"));
break;
case LUA_TNIL:
@@ -393,27 +376,27 @@ Common::String GetLuaValueInfo(lua_State *L, int StackIndex) {
break;
default:
- lua_pushfstring(L, "%s: %p", luaL_typename(L, StackIndex), lua_topointer(L, StackIndex));
+ lua_pushfstring(L, "%s: %p", luaL_typename(L, stackIndex), lua_topointer(L, stackIndex));
break;
}
- Common::String Result(lua_tostring(L, -1));
+ Common::String result(lua_tostring(L, -1));
lua_pop(L, 1);
- return Result;
+ return result;
}
}
namespace Sword25 {
-Common::String LuaBindhelper::StackDump(lua_State *L) {
+Common::String LuaBindhelper::stackDump(lua_State *L) {
Common::String oss;
int i = lua_gettop(L);
oss += "------------------- Stack Dump -------------------\n";
while (i) {
- oss += i + ": " + GetLuaValueInfo(L, i) + "\n";
+ oss += i + ": " + getLuaValueInfo(L, i) + "\n";
i--;
}
@@ -422,7 +405,7 @@ Common::String LuaBindhelper::StackDump(lua_State *L) {
return oss;
}
-Common::String LuaBindhelper::TableDump(lua_State *L) {
+Common::String LuaBindhelper::tableDump(lua_State *L) {
Common::String oss;
oss += "------------------- Table Dump -------------------\n";
@@ -430,7 +413,7 @@ Common::String LuaBindhelper::TableDump(lua_State *L) {
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
// Get the value of the current element on top of the stack, including the index
- oss += GetLuaValueInfo(L, -2) + " : " + GetLuaValueInfo(L, -1) + "\n";
+ oss += getLuaValueInfo(L, -2) + " : " + getLuaValueInfo(L, -1) + "\n";
// Pop value from the stack. The index is then ready for the next call to lua_next()
lua_pop(L, 1);