[lua] Implement Sys.getEnv and Timer.stamp for lua-vanilla mode#12865
[lua] Implement Sys.getEnv and Timer.stamp for lua-vanilla mode#12865jdonaldson wants to merge 1 commit into
Conversation
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. |
63c33e3 to
95e342b
Compare
|
Friendly ping on this one — wanted to check whether my Mar 27 reply changed your thinking on To recap the tradeoff: Three options I see, happy to go with whichever you prefer:
Just rebased onto development to clear any merge-ref staleness. |
95e342b to
701cd14
Compare
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 HaxeFoundation#12843 (hxcoro with -D lua-vanilla).
701cd14 to
7f7bcd7
Compare
|
Dropped the The PR now just implements |
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