LUA: Remove references to Sword25 (#1833)

This commit is contained in:
Cameron Cawley 2019-09-06 08:38:14 +01:00 committed by Filippos Karapetis
parent 1c8a7800da
commit 713fe80b47
5 changed files with 37 additions and 37 deletions

View file

@ -56,6 +56,6 @@ SerializedDouble encodeDouble(double value);
*/ */
double decodeDouble(SerializedDouble value); double decodeDouble(SerializedDouble value);
} // End of namespace Sword25 } // End of namespace Util
#endif #endif

View file

@ -521,7 +521,7 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
typedef struct LoadF { typedef struct LoadF {
int extraline; int extraline;
Sword25::Sword25FileProxy *f; Lua::LuaFileProxy *f;
char buff[LUAL_BUFFERSIZE]; char buff[LUAL_BUFFERSIZE];
} LoadF; } LoadF;
@ -557,7 +557,7 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
lf.extraline = 0; lf.extraline = 0;
lua_pushfstring(L, "@%s", filename); lua_pushfstring(L, "@%s", filename);
lf.f = new Sword25::Sword25FileProxy(filename, "r"); lf.f = new Lua::LuaFileProxy(filename, "r");
/* /*
if (filename == NULL) { if (filename == NULL) {
lua_pushliteral(L, "=stdin"); lua_pushliteral(L, "=stdin");

View file

@ -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 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) { static int io_type (lua_State *L) {
return luaL_error(L, "%s", "LUA I/O has been removed in ScummVM"); 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) { static Lua::LuaFileProxy *tofile (lua_State *L) {
Sword25::Sword25FileProxy **f = tofileProxy(L); Lua::LuaFileProxy **f = tofileProxy(L);
if (*f == NULL) if (*f == NULL)
luaL_error(L, "attempt to use a closed file"); luaL_error(L, "attempt to use a closed file");
return *f; 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 ** before opening the actual file; so, if there is a memory error, the
** file is not left opened. ** file is not left opened.
*/ */
static Sword25::Sword25FileProxy **newfile (lua_State *L) { static Lua::LuaFileProxy **newfile (lua_State *L) {
Sword25::Sword25FileProxy **pf = (Sword25::Sword25FileProxy **)lua_newuserdata(L, sizeof(Sword25::Sword25FileProxy *)); Lua::LuaFileProxy **pf = (Lua::LuaFileProxy **)lua_newuserdata(L, sizeof(Lua::LuaFileProxy *));
*pf = NULL; /* file handle is currently `closed' */ *pf = NULL; /* file handle is currently `closed' */
luaL_getmetatable(L, LUA_FILEHANDLE); luaL_getmetatable(L, LUA_FILEHANDLE);
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
@ -142,7 +142,7 @@ static int io_close (lua_State *L) {
if (lua_isnone(L, 1)) if (lua_isnone(L, 1))
lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT); lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT);
Sword25::Sword25FileProxy **f = tofileProxy(L); Lua::LuaFileProxy **f = tofileProxy(L);
delete *f; delete *f;
*f = NULL; *f = NULL;
@ -151,7 +151,7 @@ static int io_close (lua_State *L) {
static int io_gc (lua_State *L) { static int io_gc (lua_State *L) {
Sword25::Sword25FileProxy **f = tofileProxy(L); Lua::LuaFileProxy **f = tofileProxy(L);
// ignore closed files // ignore closed files
if (*f != NULL) if (*f != NULL)
delete *f; delete *f;
@ -176,8 +176,8 @@ static int io_tostring (lua_State *L) {
static int io_open (lua_State *L) { static int io_open (lua_State *L) {
const char *filename = luaL_checkstring(L, 1); const char *filename = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r"); const char *mode = luaL_optstring(L, 2, "r");
Sword25::Sword25FileProxy **pf = newfile(L); Lua::LuaFileProxy **pf = newfile(L);
*pf = new Sword25::Sword25FileProxy(filename, mode); *pf = new Lua::LuaFileProxy(filename, mode);
return (*pf == NULL) ? pushresult(L, 0, filename) : 1; 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; lua_Number d;
if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
lua_pushnumber(L, d); 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); int c = getc(f);
ungetc(c, f); ungetc(c, f);
lua_pushlstring(L, NULL, 0); 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_Buffer b;
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
for (;;) { 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 rlen; // how much to read
size_t nr; // number of chars actually read size_t nr; // number of chars actually read
luaL_Buffer b; 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 nargs = lua_gettop(L) - 1;
int success; int success;
int n; 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 nargs = lua_gettop(L) - 1;
int status = 1; int status = 1;
for (; nargs--; arg++) { for (; nargs--; arg++) {

View file

@ -24,15 +24,15 @@
#include "common/config-manager.h" #include "common/config-manager.h"
#include "common/language.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")); assert(filename.contains("config.lua"));
if (mode == "r") if (mode == "r")
setupConfigFile(); 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 // 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 // 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 // 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; 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 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 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; 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; _readPos = 0;
} }
Sword25FileProxy::~Sword25FileProxy() { LuaFileProxy::~LuaFileProxy() {
if (!_settings.empty()) if (!_settings.empty())
writeSettings(); 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<size_t>(_readData.size() - _readPos, size * count); size_t bytesRead = MIN<size_t>(_readData.size() - _readPos, size * count);
memmove(ptr, &_readData.c_str()[_readPos], bytesRead); memmove(ptr, &_readData.c_str()[_readPos], bytesRead);
_readPos += bytesRead; _readPos += bytesRead;
return bytesRead / size; 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) // Loop through the provided line(s)
while (*ptr) { while (*ptr) {
if ((*ptr == '-') && (*(ptr + 1) == '-')) { if ((*ptr == '-') && (*(ptr + 1) == '-')) {
@ -112,7 +112,7 @@ size_t Sword25FileProxy::write(const char *ptr, size_t count) {
return count; return count;
} }
void Sword25FileProxy::writeSettings() { void LuaFileProxy::writeSettings() {
// Loop through the setting lines // Loop through the setting lines
const char *pSrc = _settings.c_str(); const char *pSrc = _settings.c_str();
while (*pSrc) { while (*pSrc) {
@ -149,7 +149,7 @@ void Sword25FileProxy::writeSettings() {
ConfMan.flushToDisk(); 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") if (setting == "GAME_LANGUAGE")
setLanguage(value); setLanguage(value);
else if (setting == "GAME_SUBTITLES") 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 * 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")); Common::Language lang = Common::parseLanguage(ConfMan.get("language"));
switch (lang) { switch (lang) {
case Common::EN_ANY: case Common::EN_ANY:
@ -201,7 +201,7 @@ Common::String Sword25FileProxy::getLanguage() {
/** /**
* Set the language code fro the game * Set the language code fro the game
*/ */
void Sword25FileProxy::setLanguage(const Common::String &lang) { void LuaFileProxy::setLanguage(const Common::String &lang) {
if (lang == "en") if (lang == "en")
ConfMan.set("language", Common::getLanguageCode(Common::EN_ANY)); ConfMan.set("language", Common::getLanguageCode(Common::EN_ANY));
else if (lang == "de") else if (lang == "de")
@ -224,4 +224,4 @@ void Sword25FileProxy::setLanguage(const Common::String &lang) {
error("Unknown language encountered"); error("Unknown language encountered");
} }
} // End of namespace Sword25 } // End of namespace Lua

View file

@ -20,18 +20,18 @@
* *
*/ */
#ifndef SWORD25_SCUMMVM_FILE_H #ifndef LUA_SCUMMVM_FILE_H
#define SWORD25_SCUMMVM_FILE_H #define LUA_SCUMMVM_FILE_H
#include "common/str.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 * 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 * settings are a properly formatted 'config.lua' file
*/ */
class Sword25FileProxy { class LuaFileProxy {
private: private:
Common::String _readData; Common::String _readData;
uint _readPos; uint _readPos;
@ -44,14 +44,14 @@ private:
void writeSettings(); void writeSettings();
void updateSetting(const Common::String &setting, const Common::String &value); void updateSetting(const Common::String &setting, const Common::String &value);
public: public:
Sword25FileProxy(const Common::String &filename, const Common::String &mode); LuaFileProxy(const Common::String &filename, const Common::String &mode);
~Sword25FileProxy(); ~LuaFileProxy();
bool eof() const { return _readPos >= _readData.size(); } bool eof() const { return _readPos >= _readData.size(); }
size_t read(void *ptr, size_t size, size_t count); size_t read(void *ptr, size_t size, size_t count);
size_t write(const char *ptr, size_t count); size_t write(const char *ptr, size_t count);
}; };
} // End of namespace Sword25 } // End of namespace Lua
#endif #endif