Skip to content

Commit 7f7bcd7

Browse files
committed
[lua] Implement Sys.getEnv and Timer.stamp for lua-vanilla mode
Sys.getEnv() was throwing NotImplementedException in lua-vanilla mode despite having a trivial vanilla Lua implementation via os.getenv(). Timer.stamp() now uses os.clock() directly on all Lua targets for subsecond precision. Sys.time() is intentionally left as notImplemented() in lua-vanilla mode: vanilla Lua's os.time() has only second-level precision, which would silently disagree with the fractional-second wall-clock time returned by Sys.time() on every other target. Subsecond wall-clock time requires luv (non-vanilla mode). Addresses #12843 (hxcoro with -D lua-vanilla).
1 parent ab70430 commit 7f7bcd7

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

std/haxe/Timer.hx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class Timer {
173173
return untyped __global__.__time_stamp();
174174
#elseif python
175175
return Sys.cpuTime();
176+
#elseif lua
177+
return lua.Os.clock();
176178
#elseif sys
177179
return Sys.time();
178180
#else

std/lua/_std/Sys.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Sys {
4646
public static inline function programPath():String return haxe.io.Path.join([getCwd(), Lua.arg[0]]);
4747
public static function getCwd():String return notImplemented();
4848
public static function setCwd(s:String):Void notImplemented();
49-
public static function getEnv(s:String):Null<String> return notImplemented();
49+
public static inline function getEnv(s:String):Null<String> return lua.Os.getenv(s);
5050
public static function putEnv(s:String, v:Null<String>):Void notImplemented();
5151
public static inline function setTimeLocale(loc:String):Bool return lua.Os.setlocale(loc) != null;
5252
public static function sleep(seconds:Float):Void notImplemented();

0 commit comments

Comments
 (0)