diff --git a/common/lua/double_serialization.h b/common/lua/double_serialization.h index af58d03c17c7..426a7f047d13 100644 --- a/common/lua/double_serialization.h +++ b/common/lua/double_serialization.h @@ -56,6 +56,6 @@ SerializedDouble encodeDouble(double value); */ double decodeDouble(SerializedDouble value); -} // End of namespace Sword25 +} // End of namespace Util #endif diff --git a/common/lua/lauxlib.cpp b/common/lua/lauxlib.cpp index 116d19dfcea4..59a7d51a2721 100644 --- a/common/lua/lauxlib.cpp +++ b/common/lua/lauxlib.cpp @@ -521,7 +521,7 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { typedef struct LoadF { int extraline; - Sword25::Sword25FileProxy *f; + Lua::LuaFileProxy *f; char buff[LUAL_BUFFERSIZE]; } LoadF; @@ -557,7 +557,7 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) { lf.extraline = 0; lua_pushfstring(L, "@%s", filename); - lf.f = new Sword25::Sword25FileProxy(filename, "r"); + lf.f = new Lua::LuaFileProxy(filename, "r"); /* if (filename == NULL) { lua_pushliteral(L, "=stdin"); diff --git a/common/lua/liolib.cpp b/common/lua/liolib.cpp index 20d716498f3d..5145088734bd 100644 --- a/common/lua/liolib.cpp +++ b/common/lua/liolib.cpp @@ -52,7 +52,7 @@ static void fileerror (lua_State *L, int arg, const char *filename) { */ #define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) -#define tofileProxy(L) ((Sword25::Sword25FileProxy **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) +#define tofileProxy(L) ((Lua::LuaFileProxy **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) static int io_type (lua_State *L) { return luaL_error(L, "%s", "LUA I/O has been removed in ScummVM"); @@ -71,8 +71,8 @@ static int io_type (lua_State *L) { */ } -static Sword25::Sword25FileProxy *tofile (lua_State *L) { - Sword25::Sword25FileProxy **f = tofileProxy(L); +static Lua::LuaFileProxy *tofile (lua_State *L) { + Lua::LuaFileProxy **f = tofileProxy(L); if (*f == NULL) luaL_error(L, "attempt to use a closed file"); return *f; @@ -84,8 +84,8 @@ static Sword25::Sword25FileProxy *tofile (lua_State *L) { ** before opening the actual file; so, if there is a memory error, the ** file is not left opened. */ -static Sword25::Sword25FileProxy **newfile (lua_State *L) { - Sword25::Sword25FileProxy **pf = (Sword25::Sword25FileProxy **)lua_newuserdata(L, sizeof(Sword25::Sword25FileProxy *)); +static Lua::LuaFileProxy **newfile (lua_State *L) { + Lua::LuaFileProxy **pf = (Lua::LuaFileProxy **)lua_newuserdata(L, sizeof(Lua::LuaFileProxy *)); *pf = NULL; /* file handle is currently `closed' */ luaL_getmetatable(L, LUA_FILEHANDLE); lua_setmetatable(L, -2); @@ -142,7 +142,7 @@ static int io_close (lua_State *L) { if (lua_isnone(L, 1)) lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT); - Sword25::Sword25FileProxy **f = tofileProxy(L); + Lua::LuaFileProxy **f = tofileProxy(L); delete *f; *f = NULL; @@ -151,7 +151,7 @@ static int io_close (lua_State *L) { static int io_gc (lua_State *L) { - Sword25::Sword25FileProxy **f = tofileProxy(L); + Lua::LuaFileProxy **f = tofileProxy(L); // ignore closed files if (*f != NULL) delete *f; @@ -176,8 +176,8 @@ static int io_tostring (lua_State *L) { static int io_open (lua_State *L) { const char *filename = luaL_checkstring(L, 1); const char *mode = luaL_optstring(L, 2, "r"); - Sword25::Sword25FileProxy **pf = newfile(L); - *pf = new Sword25::Sword25FileProxy(filename, mode); + Lua::LuaFileProxy **pf = newfile(L); + *pf = new Lua::LuaFileProxy(filename, mode); return (*pf == NULL) ? pushresult(L, 0, filename) : 1; } @@ -291,7 +291,7 @@ static int io_lines (lua_State *L) { */ /* -static int read_number (lua_State *L, Sword25::Sword25FileProxy *f) { +static int read_number (lua_State *L, Lua::LuaFileProxy *f) { lua_Number d; if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { lua_pushnumber(L, d); @@ -301,7 +301,7 @@ static int read_number (lua_State *L, Sword25::Sword25FileProxy *f) { } -static int test_eof (lua_State *L, Sword25::Sword25FileProxy *f) { +static int test_eof (lua_State *L, Lua::LuaFileProxy *f) { int c = getc(f); ungetc(c, f); lua_pushlstring(L, NULL, 0); @@ -309,7 +309,7 @@ static int test_eof (lua_State *L, Sword25::Sword25FileProxy *f) { } -static int read_line (lua_State *L, Sword25::Sword25FileProxy *f) { +static int read_line (lua_State *L, Lua::LuaFileProxy *f) { luaL_Buffer b; luaL_buffinit(L, &b); for (;;) { @@ -331,7 +331,7 @@ static int read_line (lua_State *L, Sword25::Sword25FileProxy *f) { } -static int read_chars (lua_State *L, Sword25::Sword25FileProxy *f, size_t n) { +static int read_chars (lua_State *L, Lua::LuaFileProxy *f, size_t n) { size_t rlen; // how much to read size_t nr; // number of chars actually read luaL_Buffer b; @@ -349,7 +349,7 @@ static int read_chars (lua_State *L, Sword25::Sword25FileProxy *f, size_t n) { } -static int g_read (lua_State *L, Sword25::Sword25FileProxy *f, int first) { +static int g_read (lua_State *L, Lua::LuaFileProxy *f, int first) { int nargs = lua_gettop(L) - 1; int success; int n; @@ -433,7 +433,7 @@ static int io_readline (lua_State *L) { /* }====================================================== */ -static int g_write (lua_State *L, Sword25::Sword25FileProxy *f, int arg) { +static int g_write (lua_State *L, Lua::LuaFileProxy *f, int arg) { int nargs = lua_gettop(L) - 1; int status = 1; for (; nargs--; arg++) { diff --git a/common/lua/scummvm_file.cpp b/common/lua/scummvm_file.cpp index fb3115608240..1a5af0fb4db3 100644 --- a/common/lua/scummvm_file.cpp +++ b/common/lua/scummvm_file.cpp @@ -24,15 +24,15 @@ #include "common/config-manager.h" #include "common/language.h" -namespace Sword25 { +namespace Lua { -Sword25FileProxy::Sword25FileProxy(const Common::String &filename, const Common::String &mode) { +LuaFileProxy::LuaFileProxy(const Common::String &filename, const Common::String &mode) { assert(filename.contains("config.lua")); if (mode == "r") setupConfigFile(); } -Common::String Sword25FileProxy::formatDouble(double value) { +Common::String LuaFileProxy::formatDouble(double value) { // This is a bit hackish. The point of it is that it's important that // we ignore the locale decimal mark and force it to be a point. If it // would happen to be a comma instead, it seems that it's seen as two @@ -51,7 +51,7 @@ Common::String Sword25FileProxy::formatDouble(double value) { return out; } -void Sword25FileProxy::setupConfigFile() { +void LuaFileProxy::setupConfigFile() { double sfxVolume = !ConfMan.hasKey("sfx_volume") ? 1.0 : 1.0 * ConfMan.getInt("sfx_volume") / 255.0; double musicVolume = !ConfMan.hasKey("music_volume") ? 0.5 : 1.0 * ConfMan.getInt("music_volume") / 255.0; double speechVolume = !ConfMan.hasKey("speech_volume") ? 1.0 : 1.0 * ConfMan.getInt("speech_volume") / 255.0; @@ -75,19 +75,19 @@ SFX_SPEECH_VOLUME = %s\r\n", _readPos = 0; } -Sword25FileProxy::~Sword25FileProxy() { +LuaFileProxy::~LuaFileProxy() { if (!_settings.empty()) writeSettings(); } -size_t Sword25FileProxy::read(void *ptr, size_t size, size_t count) { +size_t LuaFileProxy::read(void *ptr, size_t size, size_t count) { size_t bytesRead = MIN(_readData.size() - _readPos, size * count); memmove(ptr, &_readData.c_str()[_readPos], bytesRead); _readPos += bytesRead; return bytesRead / size; } -size_t Sword25FileProxy::write(const char *ptr, size_t count) { +size_t LuaFileProxy::write(const char *ptr, size_t count) { // Loop through the provided line(s) while (*ptr) { if ((*ptr == '-') && (*(ptr + 1) == '-')) { @@ -112,7 +112,7 @@ size_t Sword25FileProxy::write(const char *ptr, size_t count) { return count; } -void Sword25FileProxy::writeSettings() { +void LuaFileProxy::writeSettings() { // Loop through the setting lines const char *pSrc = _settings.c_str(); while (*pSrc) { @@ -149,7 +149,7 @@ void Sword25FileProxy::writeSettings() { ConfMan.flushToDisk(); } -void Sword25FileProxy::updateSetting(const Common::String &setting, const Common::String &value) { +void LuaFileProxy::updateSetting(const Common::String &setting, const Common::String &value) { if (setting == "GAME_LANGUAGE") setLanguage(value); else if (setting == "GAME_SUBTITLES") @@ -171,7 +171,7 @@ void Sword25FileProxy::updateSetting(const Common::String &setting, const Common /** * Get the language code used by the game for each language it supports */ -Common::String Sword25FileProxy::getLanguage() { +Common::String LuaFileProxy::getLanguage() { Common::Language lang = Common::parseLanguage(ConfMan.get("language")); switch (lang) { case Common::EN_ANY: @@ -201,7 +201,7 @@ Common::String Sword25FileProxy::getLanguage() { /** * Set the language code fro the game */ -void Sword25FileProxy::setLanguage(const Common::String &lang) { +void LuaFileProxy::setLanguage(const Common::String &lang) { if (lang == "en") ConfMan.set("language", Common::getLanguageCode(Common::EN_ANY)); else if (lang == "de") @@ -224,4 +224,4 @@ void Sword25FileProxy::setLanguage(const Common::String &lang) { error("Unknown language encountered"); } -} // End of namespace Sword25 +} // End of namespace Lua diff --git a/common/lua/scummvm_file.h b/common/lua/scummvm_file.h index 72d2690a4d4a..6f240a8351ba 100644 --- a/common/lua/scummvm_file.h +++ b/common/lua/scummvm_file.h @@ -20,18 +20,18 @@ * */ -#ifndef SWORD25_SCUMMVM_FILE_H -#define SWORD25_SCUMMVM_FILE_H +#ifndef LUA_SCUMMVM_FILE_H +#define LUA_SCUMMVM_FILE_H #include "common/str.h" -namespace Sword25 { +namespace Lua { /** * The following class acts as a proxy interface to the I/O code, pretending that the ScummVM * settings are a properly formatted 'config.lua' file */ -class Sword25FileProxy { +class LuaFileProxy { private: Common::String _readData; uint _readPos; @@ -44,14 +44,14 @@ class Sword25FileProxy { void writeSettings(); void updateSetting(const Common::String &setting, const Common::String &value); public: - Sword25FileProxy(const Common::String &filename, const Common::String &mode); - ~Sword25FileProxy(); + LuaFileProxy(const Common::String &filename, const Common::String &mode); + ~LuaFileProxy(); bool eof() const { return _readPos >= _readData.size(); } size_t read(void *ptr, size_t size, size_t count); size_t write(const char *ptr, size_t count); }; -} // End of namespace Sword25 +} // End of namespace Lua #endif