Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUA: Remove references to Sword25 #1833

Merged
merged 1 commit into from Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/lua/double_serialization.h
Expand Up @@ -56,6 +56,6 @@ SerializedDouble encodeDouble(double value);
*/
double decodeDouble(SerializedDouble value);

} // End of namespace Sword25
} // End of namespace Util

#endif
4 changes: 2 additions & 2 deletions common/lua/lauxlib.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down
30 changes: 15 additions & 15 deletions common/lua/liolib.cpp
Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand All @@ -301,15 +301,15 @@ 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);
return (c != EOF);
}


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 (;;) {
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down
24 changes: 12 additions & 12 deletions common/lua/scummvm_file.cpp
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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<size_t>(_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) == '-')) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand Down Expand Up @@ -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")
Expand All @@ -224,4 +224,4 @@ void Sword25FileProxy::setLanguage(const Common::String &lang) {
error("Unknown language encountered");
}

} // End of namespace Sword25
} // End of namespace Lua
14 changes: 7 additions & 7 deletions common/lua/scummvm_file.h
Expand Up @@ -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;
Expand All @@ -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