-
Notifications
You must be signed in to change notification settings - Fork 35
/
main.nim
66 lines (53 loc) · 1.4 KB
/
main.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import nimscripter
import nimscripter/expose
import compiler/nimeval
import std/[options, os, times]
#import nicoscript
import nico
exportTo(nico,
setColor,
line,
circ,
circfill,
rect,
rectfill,
cls,
btn,
sin,
cos,
)
var
intr: Option[Interpreter]
lastModified: Time
const
fileName = "assets/example.nims"
codeImpls = implNimscriptModule(nico)
stdlib = findNimStdlibCompileTime()
when defined(emscripten):
proc reload*(script: cstring): cint {.exportc,cdecl.} =
echo "reloading script..."
echo script
echo "..."
intr = loadScript($script, codeImpls, isFile = false, modules = ["nicoscript"], stdPath = "assets/lib")
echo "done"
#if intr.isSome:
# intr.get.invoke(init)
return 0
proc gameInit() =
when defined(emscripten):
intr = loadScript(fileName, codeImpls, modules = ["nicoscript"], stdPath = "assets/lib")
#if intr.isSome:
# intr.get.invoke(init)
proc gameUpdate(dt: float32) =
when not defined(emscripten):
if lastModified < getLastModificationTime(fileName):
intr = loadScript(fileName, codeImpls, modules = ["nicoscript"], stdPath = stdlib)
lastModified = getLastModificationTime(fileName)
#if intr.isSome:
# intr.get.invoke(update, dt)
proc gameDraw() =
if intr.isSome:
intr.get.invoke(draw)
nico.init("nico","test")
nico.createWindow("nico", 128, 128, 4, false)
nico.run(gameInit, gameUpdate, gameDraw)