1
0

Fixed bindings for cFile:ReadWholeFile().

Fixes #1914
This commit is contained in:
Mattes D 2015-04-30 11:44:42 +02:00
parent 4bf3b874e3
commit 8d4a87d2c4
2 changed files with 44 additions and 8 deletions

View File

@ -253,12 +253,13 @@ static int tolua_InflateString(lua_State * tolua_S)
static int tolua_StringSplit(lua_State * tolua_S)
{
// Get the params:
cLuaState LuaState(tolua_S);
std::string str = (std::string)tolua_tocppstring(LuaState, 1, 0);
std::string delim = (std::string)tolua_tocppstring(LuaState, 2, 0);
AString str, delim;
LuaState.GetStackValues(1, str, delim);
AStringVector Split = StringSplit(str, delim);
LuaState.Push(Split);
// Execute and push the result:
LuaState.Push(StringSplit(str, delim));
return 1;
}
@ -472,6 +473,7 @@ cPluginLua * GetLuaPlugin(lua_State * L)
static int tolua_cFile_GetFolderContents(lua_State * tolua_S)
{
// Check params:
cLuaState LuaState(tolua_S);
if (
!LuaState.CheckParamUserTable(1, "cFile") ||
@ -482,10 +484,38 @@ static int tolua_cFile_GetFolderContents(lua_State * tolua_S)
return 0;
}
AString Folder = (AString)tolua_tocppstring(LuaState, 2, 0);
// Get params:
AString Folder;
LuaState.GetStackValues(2, Folder);
AStringVector Contents = cFile::GetFolderContents(Folder);
LuaState.Push(Contents);
// Execute and push result:
LuaState.Push(cFile::GetFolderContents(Folder));
return 1;
}
static int tolua_cFile_ReadWholeFile(lua_State * tolua_S)
{
// Check params:
cLuaState LuaState(tolua_S);
if (
!LuaState.CheckParamUserTable(1, "cFile") ||
!LuaState.CheckParamString (2) ||
!LuaState.CheckParamEnd (3)
)
{
return 0;
}
// Get params:
AString FileName;
LuaState.GetStackValues(2, FileName);
// Execute and push result:
LuaState.Push(cFile::ReadWholeFile(FileName));
return 1;
}
@ -3719,6 +3749,7 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_beginmodule(tolua_S, "cFile");
tolua_function(tolua_S, "GetFolderContents", tolua_cFile_GetFolderContents);
tolua_function(tolua_S, "ReadWholeFile", tolua_cFile_ReadWholeFile);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cBlockArea");

View File

@ -124,9 +124,14 @@ public:
/** Creates a new folder with the specified name. Returns true if successful. Path may be relative or absolute */
static bool CreateFolder(const AString & a_FolderPath);
/** Returns the entire contents of the specified file as a string. Returns empty string on error. */
// tolua_end
/** Returns the entire contents of the specified file as a string. Returns empty string on error.
Exported manually in ManualBindings.cpp due to #1914 - ToLua code doesn't work well with binary files. */
static AString ReadWholeFile(const AString & a_FileName);
// tolua_begin
/** Returns a_FileName with its extension changed to a_NewExt.
a_FileName may contain path specification. */
static AString ChangeFileExt(const AString & a_FileName, const AString & a_NewExt);