diff options
author | Darshan Shaligram <dshaligram@users.sourceforge.net> | 2011-01-09 17:06:00 +0530 |
---|---|---|
committer | Darshan Shaligram <dshaligram@users.sourceforge.net> | 2011-01-09 19:26:21 +0530 |
commit | ca4d01dab5f9cd5df7565e9400feab64ff366c47 (patch) | |
tree | a5b82e1a0b866a6e3cb3059d26508be0b2e80be5 /crawl-ref/source/l_file.cc | |
parent | 62cc1eb26833210fb1a4db21ba7f0e650fb8c2a9 (diff) | |
download | crawl-ref-ca4d01dab5f9cd5df7565e9400feab64ff366c47.tar.gz crawl-ref-ca4d01dab5f9cd5df7565e9400feab64ff366c47.zip |
Use FunctionWrapper objects instead of raw functions for all markers.
All markers that use function parameters now take FunctionWrappers instead of
raw functions. FunctionWrappers are saved by name instead of saving the
function's Lua bytecode, thus fixing the save incompatibility issue due to Lua
bytecode being incompatible across platforms.
Diffstat (limited to 'crawl-ref/source/l_file.cc')
-rw-r--r-- | crawl-ref/source/l_file.cc | 24 |
1 files changed, 2 insertions, 22 deletions
diff --git a/crawl-ref/source/l_file.cc b/crawl-ref/source/l_file.cc index 082e2512a9..efa5f279b4 100644 --- a/crawl-ref/source/l_file.cc +++ b/crawl-ref/source/l_file.cc @@ -31,17 +31,13 @@ static int file_marshall(lua_State *ls) if (lua_gettop(ls) != 2) luaL_error(ls, "Need two arguments: tag header and value"); writer &th(*static_cast<writer*>(lua_touserdata(ls, 1))); + ASSERT(!lua_isfunction(ls, 2)); if (lua_isnumber(ls, 2)) marshallInt(th, luaL_checklong(ls, 2)); else if (lua_isboolean(ls, 2)) marshallByte(th, lua_toboolean(ls, 2)); else if (lua_isstring(ls, 2)) marshallString(th, lua_tostring(ls, 2)); - else if (lua_isfunction(ls, 2)) - { - dlua_chunk chunk(ls); - marshallString(th, chunk.compiled_chunk()); - } return (0); } @@ -72,23 +68,12 @@ static int file_unmarshall_string(lua_State *ls) return (1); } -static int file_unmarshall_fn(lua_State *ls) -{ - if (lua_gettop(ls) != 1) - luaL_error(ls, "Need reader as one argument"); - reader &th(*static_cast<reader*>(lua_touserdata(ls, 1))); - const std::string s(unmarshallString(th, LUA_CHUNK_MAX_SIZE)); - dlua_chunk chunk = dlua_chunk::precompiled(s); - if (chunk.load(dlua)) - lua_pushnil(ls); - return (1); -} - enum lua_persist_type { LPT_NONE, LPT_NUMBER, LPT_STRING, + // [ds] No longer supported for save portability: LPT_FUNCTION, LPT_NIL, LPT_BOOLEAN, @@ -108,8 +93,6 @@ static int file_marshall_meta(lua_State *ls) ptype = LPT_BOOLEAN; else if (lua_isstring(ls, 2)) ptype = LPT_STRING; - else if (lua_isfunction(ls, 2)) - ptype = LPT_FUNCTION; else if (lua_isnil(ls, 2)) ptype = LPT_NIL; else @@ -135,8 +118,6 @@ static int file_unmarshall_meta(lua_State *ls) return file_unmarshall_number(ls); case LPT_STRING: return file_unmarshall_string(ls); - case LPT_FUNCTION: - return file_unmarshall_fn(ls); case LPT_NIL: lua_pushnil(ls); return (1); @@ -215,7 +196,6 @@ static const struct luaL_reg file_dlib[] = { "unmarshall_boolean", file_unmarshall_boolean }, { "unmarshall_number", file_unmarshall_number }, { "unmarshall_string", file_unmarshall_string }, - { "unmarshall_fn", file_unmarshall_fn }, { "writefile", _file_writefile }, { "datadir_files", _file_datadir_files }, { "datadir_files_recursive", _file_datadir_files_recursive }, |