Symptom
os.time() (and os.date, os.clock, os.difftime) raise "attempt to call a nil value (field 'X' on global 'os')". The os table itself exists — it is auto-allocated by the default sandbox in lib/lua.ex:45-50 to host the raise-on-call stubs for os.execute/exit/getenv/remove/rename/tmpname — but no actual os.* functions are installed.
Repro
print(type(os)) -- "table"
print(type(os.time)) -- "nil"
_ENV.GLOB1 = math.floor(os.time()) % 2 -- runtime type error
Blocks test/lua53_tests/constructs.lua at line 237.
Where the gap is
lib/lua/vm/stdlib.ex:22-56 installs String, Math, Table, Utf8, and Debug libraries — no Os. There is no lib/lua/vm/stdlib/os.ex.
The sandbox in lib/lua.ex only knows about the side-effectful entries (execute, exit, getenv, remove, rename, tmpname); the side-effect-free helpers (time, date, clock, difftime) need their own stdlib install path.
Proposed scope
Add Lua.VM.Stdlib.Os mirroring the layout of Lua.VM.Stdlib.Math. Minimum surface:
| Function |
Notes |
os.time([table]) |
seconds since epoch; mirrors :os.system_time(:second) for the no-arg form |
os.date([format[, time]]) |
format strings *t, !*t, and %-format via :calendar / Calendar.strftime |
os.clock() |
CPU time in seconds (:erlang.statistics(:runtime)) |
os.difftime(t2, t1) |
trivial subtract |
os.getenv(name) |
safe to stub — returns nil always (the sandbox entry still raises if not excluded) |
os.execute, os.exit, os.remove, os.rename, os.tmpname stay sandboxed by default.
Suite impact
Unlocks lines 237..248 of constructs.lua immediately. May also progress other suite files that touch os.time for seeding (math.lua sometimes does).
Related
Symptom
os.time()(andos.date,os.clock,os.difftime) raise "attempt to call a nil value (field 'X' on global 'os')". Theostable itself exists — it is auto-allocated by the default sandbox inlib/lua.ex:45-50to host the raise-on-call stubs foros.execute/exit/getenv/remove/rename/tmpname— but no actualos.*functions are installed.Repro
Blocks
test/lua53_tests/constructs.luaat line 237.Where the gap is
lib/lua/vm/stdlib.ex:22-56installsString,Math,Table,Utf8, andDebuglibraries — noOs. There is nolib/lua/vm/stdlib/os.ex.The sandbox in
lib/lua.exonly knows about the side-effectful entries (execute,exit,getenv,remove,rename,tmpname); the side-effect-free helpers (time,date,clock,difftime) need their own stdlib install path.Proposed scope
Add
Lua.VM.Stdlib.Osmirroring the layout ofLua.VM.Stdlib.Math. Minimum surface:os.time([table]):os.system_time(:second)for the no-arg formos.date([format[, time]])*t,!*t, and%-format via:calendar/Calendar.strftimeos.clock():erlang.statistics(:runtime))os.difftime(t2, t1)os.getenv(name)nilalways (the sandbox entry still raises if not excluded)os.execute,os.exit,os.remove,os.rename,os.tmpnamestay sandboxed by default.Suite impact
Unlocks lines 237..248 of constructs.lua immediately. May also progress other suite files that touch
os.timefor seeding (math.lua sometimes does).Related