about summary refs log tree commit diff
path: root/pkg/lang/modules/core/natives.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-08-29 23:57:50 +0000
committerMel <einebeere@gmail.com>2022-08-29 23:57:50 +0000
commit6f5014e6589ca6b60c12e1ce94685c122eb6d590 (patch)
tree3e25514619b0e7632628d174557d63241ad8aee5 /pkg/lang/modules/core/natives.go
parentafb8ae0018a5947d5e33c9f59d31c5009028e79d (diff)
downloadjinx-6f5014e6589ca6b60c12e1ce94685c122eb6d590.tar.zst
jinx-6f5014e6589ca6b60c12e1ce94685c122eb6d590.zip
Add core sleep function
Diffstat (limited to 'pkg/lang/modules/core/natives.go')
-rw-r--r--pkg/lang/modules/core/natives.go13
1 files changed, 13 insertions, 0 deletions
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 {