[lua] Implement Sys.time, Sys.getEnv, and Timer.stamp for lua-vanilla mode#12865
[lua] Implement Sys.time, Sys.getEnv, and Timer.stamp for lua-vanilla mode#12865jdonaldson wants to merge 1 commit intoHaxeFoundation:developmentfrom
Conversation
… mode Sys.time() and Sys.getEnv() were throwing NotImplementedException in lua-vanilla mode despite having trivial vanilla Lua implementations via os.time() and os.getenv(). Timer.stamp() now uses os.clock() directly on all Lua targets for subsecond precision. Addresses HaxeFoundation#12843 (hxcoro with -D lua-vanilla).
I think we should use os.clock for both, unless we specify a behaviour that requires otherwise. That way EDIT: Lua docs say:
We already use it for |
|
I looked at what every other target does for
Every target returns wall-clock time (C++ is the outlier with monotonic). Using The precision is unfortunate, but vanilla Lua simply doesn't have a subsecond wall-clock API without external libraries. For |
|
I remember not using os.time() for this reason. I think it might be ok for lua-vanilla, maybe with some sort of warning? I wasn't using it for anything critical, so I'm all ears on what the right tradeoff is here. |
Summary
Sys.time()— useos.time()instead of throwing. Note: integer-second precision only (vs microsecond precision with luv). Open question: should we emit a compiler warning here?Sys.getEnv()— useos.getenv()instead of throwingTimer.stamp()— useos.clock()directly on all Lua targets (subsecond precision, avoids theSys.time()path entirely)These are the remaining Haxe-side changes needed for #12843 (hxcoro with
-D lua-vanilla). The bit ops part was already resolved by #12599.Open question
os.time()only returns integer seconds. Should we warn at compile time whenSys.time()is used inlua-vanillamode, since users might expect subsecond precision? Or is it fine as-is since the docs don't guarantee precision?Test plan
Timer.stamp()returns subsecond values on LuaSys.getEnv()works in lua-vanilla mode