call "path.getDefaultSeparator" allowing it to be overridden.

This commit is contained in:
Tom van Dijck 2017-08-07 16:34:13 -07:00
parent dce5e604dc
commit cf45d30f5b
2 changed files with 14 additions and 13 deletions

View File

@ -267,3 +267,14 @@
return p:match("^(.*)"..ext.."$")..newext
end
--
-- Get the default seperator for path.translate
--
function path.getDefaultSeparator()
if os.istarget('windows') then
return '\\'
else
return '/'
end
end

View File

@ -28,25 +28,15 @@ static void translate(char* result, const char* value, const char sep)
int path_translate(lua_State* L)
{
const char* os;
const char* sep;
char buffer[0x4000];
if (lua_gettop(L) == 1) {
// Get target OS
lua_getglobal(L, "os");
lua_getfield(L, -1, "target");
lua_getglobal(L, "path");
lua_getfield(L, -1, "getDefaultSeparator");
lua_call(L, 0, 1);
os = luaL_checkstring(L, -1);
sep = luaL_checkstring(L, -1);
lua_pop(L, 2);
// Use target OS separator
if (strcmp(os, "windows") == 0) {
sep = "\\";
}
else {
sep = "/";
}
}
else {
sep = luaL_checkstring(L, 2);