lua: os stub (time/clock/date/difftime/getenv/...) +8 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
This commit is contained in:
@@ -1238,3 +1238,80 @@
|
||||
(define print lua-print)
|
||||
(define tostring lua-tostring)
|
||||
(define tonumber lua-tonumber)
|
||||
|
||||
;; ── os library (minimal stub — no real clock/filesystem) ──────
|
||||
(define os {})
|
||||
(define __os-counter 0)
|
||||
|
||||
(define
|
||||
lua-os-time
|
||||
(fn (&rest args)
|
||||
(begin
|
||||
(set! __os-counter (+ __os-counter 1))
|
||||
__os-counter)))
|
||||
|
||||
(define
|
||||
lua-os-clock
|
||||
(fn ()
|
||||
(/ __os-counter 1000)))
|
||||
|
||||
(define
|
||||
lua-os-difftime
|
||||
(fn (t2 t1) (- t2 t1)))
|
||||
|
||||
(define
|
||||
lua-os-date
|
||||
(fn (&rest args)
|
||||
(let ((fmt (if (> (len args) 0) (first args) "%c")))
|
||||
(cond
|
||||
((= fmt "*t")
|
||||
(let ((d {}))
|
||||
(begin
|
||||
(dict-set! d "year" 1970)
|
||||
(dict-set! d "month" 1)
|
||||
(dict-set! d "day" 1)
|
||||
(dict-set! d "hour" 0)
|
||||
(dict-set! d "min" 0)
|
||||
(dict-set! d "sec" 0)
|
||||
(dict-set! d "wday" 5)
|
||||
(dict-set! d "yday" 1)
|
||||
(dict-set! d "isdst" false)
|
||||
d)))
|
||||
(else "1970-01-01 00:00:00")))))
|
||||
|
||||
(define
|
||||
lua-os-getenv
|
||||
(fn (name) nil))
|
||||
|
||||
(define
|
||||
lua-os-exit
|
||||
(fn (&rest args) (error "lua: os.exit called")))
|
||||
|
||||
(define
|
||||
lua-os-remove
|
||||
(fn (name)
|
||||
(list (quote lua-multi) nil "os.remove not supported")))
|
||||
|
||||
(define
|
||||
lua-os-rename
|
||||
(fn (a b)
|
||||
(list (quote lua-multi) nil "os.rename not supported")))
|
||||
|
||||
(define
|
||||
lua-os-tmpname
|
||||
(fn () "/tmp/lua_stub"))
|
||||
|
||||
(define
|
||||
lua-os-execute
|
||||
(fn (&rest args) 0))
|
||||
|
||||
(dict-set! os "time" lua-os-time)
|
||||
(dict-set! os "clock" lua-os-clock)
|
||||
(dict-set! os "difftime" lua-os-difftime)
|
||||
(dict-set! os "date" lua-os-date)
|
||||
(dict-set! os "getenv" lua-os-getenv)
|
||||
(dict-set! os "exit" lua-os-exit)
|
||||
(dict-set! os "remove" lua-os-remove)
|
||||
(dict-set! os "rename" lua-os-rename)
|
||||
(dict-set! os "tmpname" lua-os-tmpname)
|
||||
(dict-set! os "execute" lua-os-execute)
|
||||
|
||||
Reference in New Issue
Block a user