From 7f7bcd7af73ec8af2e95d9ddd376b90489d79a2a Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Wed, 25 Mar 2026 11:58:17 +0100 Subject: [PATCH] [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). --- std/haxe/Timer.hx | 2 ++ std/lua/_std/Sys.hx | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/std/haxe/Timer.hx b/std/haxe/Timer.hx index ccf04173aa7..6b75fb18c1f 100644 --- a/std/haxe/Timer.hx +++ b/std/haxe/Timer.hx @@ -173,6 +173,8 @@ class Timer { return untyped __global__.__time_stamp(); #elseif python return Sys.cpuTime(); + #elseif lua + return lua.Os.clock(); #elseif sys return Sys.time(); #else diff --git a/std/lua/_std/Sys.hx b/std/lua/_std/Sys.hx index 1e81386f049..e4c9ea4ffea 100644 --- a/std/lua/_std/Sys.hx +++ b/std/lua/_std/Sys.hx @@ -46,7 +46,7 @@ class Sys { public static inline function programPath():String return haxe.io.Path.join([getCwd(), Lua.arg[0]]); public static function getCwd():String return notImplemented(); public static function setCwd(s:String):Void notImplemented(); - public static function getEnv(s:String):Null return notImplemented(); + public static inline function getEnv(s:String):Null return lua.Os.getenv(s); public static function putEnv(s:String, v:Null):Void notImplemented(); public static inline function setTimeLocale(loc:String):Bool return lua.Os.setlocale(loc) != null; public static function sleep(seconds:Float):Void notImplemented();