Skip to content

Commit

Permalink
[lua] use luv for sys environment variable queries/updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonaldson committed Sep 4, 2018
1 parent 6d20cac commit 9d75bec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 47 deletions.
43 changes: 26 additions & 17 deletions std/lua/_std/Sys.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@
* DEALINGS IN THE SOFTWARE.
*/

using lua.NativeStringTools;
import lua.Package;
import lua.Boot;
import lua.Io;
import lua.Lua;
import lua.Table;
import lua.TableTools;
import lua.Os;
import lua.FileHandle;
import lua.Io;
import lua.Boot;
import lua.lib.luautf8.Utf8;
import lua.lib.luv.Misc;
import sys.io.FileInput;
import sys.io.FileOutput;

Expand All @@ -43,7 +40,7 @@ class Sys {
return lua.Lib.println(v);
}
public inline static function args() : Array<String> {
var targs = lua.PairTools.copy(lua.Lua.arg);
var targs = lua.PairTools.copy(Lua.arg);
var args = lua.Lib.tableToArray(targs);
return args;
}
Expand All @@ -64,7 +61,7 @@ class Sys {
}

public inline static function getChar(echo : Bool) : Int {
return lua.Io.read(1).byte();
return lua.Io.read().charCodeAt(0);
}

static function getSystemName() : String {
Expand All @@ -78,30 +75,42 @@ class Sys {

public static function environment() : Map<String,String> {
var map = new Map<String,String>();
var f = function(k,v) map.set(k,v);
untyped __lua__("for k,v in lua.lib.environ.Environ.enum() do f(k,v) end");
return map;
var cmd = switch(Sys.systemName()){
case "Windows" : 'SET';
default : 'printenv';
}
var p = new sys.io.Process(cmd,[]);
var code = p.exitCode(true);
var out = p.stdout.readAll().toString();
var lines = out.split("\n");
var m = new Map<String,String>();
for (l in lines){
var parts = l.split("=");
m.set(parts.shift(), parts.join("="));
}
return m;
}

@:deprecated("Use programPath instead") public static function executablePath() : String {
return lua.lib.luv.Misc.exepath();
return Misc.exepath();
}

public inline static function programPath() : String {
return haxe.io.Path.join([getCwd(), Lua.arg[0]]);
}

public inline static function getCwd() : String
return lua.lib.luv.Misc.cwd();
return Misc.cwd();

public inline static function setCwd(s : String) : Void
lua.lib.luv.Misc.chdir(s);
Misc.chdir(s);

public inline static function getEnv(s : String) : String {
return lua.Os.getenv(s);
return Misc.os_getenv(s);
}

public inline static function putEnv(s : String, v : String ) : Void {
lua.lib.environ.Environ.setenv(s,v);
Misc.os_setenv(s,v);
}

public inline static function setTimeLocale(loc : String) : Bool {
Expand Down
30 changes: 0 additions & 30 deletions std/lua/lib/environ/Environ.hx

This file was deleted.

3 changes: 3 additions & 0 deletions std/lua/lib/luv/Misc.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ extern class Misc {
public static function get_free_memory() : Int;
public static function getpid() : Int;

public static function os_getenv(env : String) : String;
public static function os_setenv(env : String, value : String) : Void;

// TODO Windows only?
public static function getuid() : Int;
public static function setuid(from : Int, to : Int) : String;
Expand Down

0 comments on commit 9d75bec

Please sign in to comment.