Skip to content

Commit 3ddfab5

Browse files
authored
[Space Lua] Extend os (#1836)
1 parent e0182b3 commit 3ddfab5

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

client/space_lua/stdlib/os.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,9 @@ export const osApi = new LuaTable({
365365
return luaFormatTime(fmt, d, utc);
366366
},
367367
),
368+
369+
// Returns an approximation of CPU time used by the program in seconds.
370+
clock: new LuaBuiltinFunction((_sf): number => {
371+
return performance.now() / 1000.0;
372+
}),
368373
});

client/space_lua/stdlib/os_test.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,15 @@ assert(type(err) == "string")
168168

169169
-- Repeated specifiers
170170
assertEquals(os.date("!%Y%Y", ts), "20062006")
171+
172+
-- os.clock
173+
-- Returns a number (seconds)
174+
assert(type(os.clock()) == "number")
175+
176+
-- Must be non-negative
177+
assert(os.clock() >= 0)
178+
179+
-- Monotonically non-decreasing
180+
local c1 = os.clock()
181+
local c2 = os.clock()
182+
assert(c2 >= c1)

0 commit comments

Comments
 (0)