From 6f5014e6589ca6b60c12e1ce94685c122eb6d590 Mon Sep 17 00:00:00 2001 From: Mel Date: Mon, 29 Aug 2022 23:57:50 +0000 Subject: Add core sleep function --- pkg/lang/modules/core/natives.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'pkg/lang/modules/core/natives.go') diff --git a/pkg/lang/modules/core/natives.go b/pkg/lang/modules/core/natives.go index 7fc9a01..3031d82 100644 --- a/pkg/lang/modules/core/natives.go +++ b/pkg/lang/modules/core/natives.go @@ -5,6 +5,7 @@ import ( "jinx/pkg/lang/vm/code" "jinx/pkg/lang/vm/executor" "jinx/pkg/lang/vm/value" + "time" ) var Natives = []any{ @@ -137,6 +138,18 @@ var Natives = []any{ return value.Value{}, exe.Write(s) }), + + n(":core:sleep", 1, func(exe executor.Exectutor, args []value.Value) (value.Value, error) { + duration, err := ensureType[value.IntData](args[0], value.IntType) + if err != nil { + return value.Value{}, err + } + + durationInMilliseconds := duration.Get() + time.Sleep(time.Duration(durationInMilliseconds) * time.Millisecond) + + return value.Value{}, nil + }), } type native struct { -- cgit 1.4.1