@@ -13,22 +13,26 @@ proc init*(jl: type Julia) =
13
13
jlVmInit()
14
14
15
15
template init* (jl: type Julia, body: untyped ) =
16
- # Pkg installation interface
17
- var packages : seq [string ]
16
+ # # Init Julia VM
17
+ var packages: seq [string ]
18
18
template Pkg(innerbody: untyped ) =
19
+ # # Pkg installation API
19
20
proc add(pkgname: string ) =
20
21
packages.add pkgname
21
22
innerbody
22
23
23
- # Embedding ressources interface
24
24
template Embed(innerbody: untyped ) =
25
+ # # Emded Julia file explicitly of from a directory
25
26
template file(filename: static [string ]) =
27
+ # # Embed file
26
28
jlEmbedFile(filename)
27
29
28
30
template dir(dirname: static [string ]) =
31
+ # # Embed directory
29
32
jlEmbedDir(dirname)
30
33
31
34
template thisDir() =
35
+ # # Embed current dir
32
36
jlEmbedDir(" " )
33
37
34
38
block :
@@ -44,6 +48,7 @@ template init*(jl: type Julia, body: untyped) =
44
48
let pkg = Julia.getModule(" Pkg" )
45
49
for pkgname in packages:
46
50
discard jlCall(pkg, " add" , pkgname)
51
+ jlUsing(pkgname)
47
52
48
53
# Eval Julia code embedded
49
54
loadJlRessources()
@@ -52,15 +57,19 @@ template init*(jl: type Julia, body: untyped) =
52
57
raise newException(JlError, " Error Julia.init() has already been initialized" )
53
58
54
59
proc exit* (jl: type Julia, exitcode: int = 0 ) =
60
+ # # Exit Julia VM
55
61
jlVmExit(exitcode.cint )
56
62
57
63
proc useModule* (jl: type Julia, modname: string ) =
64
+ # # Alias for jlUseModule. "using" is a keyword in Nim and so wasn't available
58
65
jlUseModule(modname)
59
66
60
- proc getModule* (jl: type Julia, modname: string ) : JlModule =
67
+ proc getModule* (jl: type Julia, modname: string ): JlModule =
68
+ # # Alias for jlGetModule
61
69
jlGetModule(modname)
62
70
63
71
proc includeFile* (jl: type Julia, fname: string ) =
72
+ # # Alias for jlInclude
64
73
jlInclude(fname)
65
74
66
75
# macro loadModule*(jl: type Julia, modname: untyped) =
@@ -86,21 +95,27 @@ proc `$`*(val: JlSym): string =
86
95
87
96
# typeof is taken by Nim already
88
97
proc jltypeof* (x: JlValue): JlValue =
98
+ # # Call the Julia function typeof
89
99
jlCall(" typeof" , x)
90
100
91
101
proc len* (val: JlValue): int =
102
+ # #Call length
92
103
jlCall(" length" , val).to(int )
93
104
94
105
proc firstindex* (val: JlValue): int =
106
+ # # Call firstindex
95
107
jlCall(" firstindex" , val).to(int )
96
108
97
109
proc lastindex* (val: JlValue): int =
110
+ # # Call lastindex
98
111
jlCall(" lastindex" , val).to(int )
99
112
100
113
template getproperty* (val: JlValue, propertyname: string ): JlValue =
114
+ # # Call getproperty
101
115
jlCall(" getproperty" , val, jlSym(propertyname))
102
116
103
117
template setproperty* (val: JlValue, propertyname: string , newval: untyped ) =
118
+ # # Call setproperty
104
119
discard jlCall(" setproperty!" , val, jlSym(propertyname), newval)
105
120
106
121
# ####################################################
@@ -110,26 +125,31 @@ import std/macros
110
125
111
126
{.experimental: " dotOperators" .}
112
127
113
- macro unpackVarargs_first(callee, arg_first: untyped ; arg_second: untyped , args: varargs [untyped ]):untyped =
128
+ macro unpackVarargs_first(callee, arg_first: untyped ; arg_second: untyped , args: varargs [untyped ]): untyped =
114
129
result = newCall(callee)
115
130
result .add arg_first
116
131
result .add arg_second
117
132
for a in args:
118
133
result .add a
119
134
120
135
template `.()` * (jl: type Julia, funcname: untyped , args: varargs [JlValue, toJlVal]) : JlValue =
136
+ # # Alias to call a Julia function
121
137
jlCall(astToStr(funcname), args)
122
138
123
139
template `.()` * (jlmod: JlModule, funcname: untyped , args: varargs [JlValue, toJlVal]) : JlValue =
140
+ # # Alias to call a Julia function
124
141
jlCall(jlmod, astToStr(funcname), args)
125
142
126
143
template `.()` * (jlval: JlValue, funcname: untyped , args: varargs [JlValue, toJlVal]) : JlValue =
144
+ # # Alias to call a Julia function
127
145
unpackVarargs_first(jlCall, astToStr(funcname), jlval, args)
128
146
129
147
template `.` * (jlval: JlValue, propertyname: untyped ): JlValue =
148
+ # # Alias for getproperty
130
149
getproperty(jlval, astToStr(propertyname))
131
150
132
151
template `.=` * (jlval: var JlValue, fieldname: untyped , newval: untyped ) =
152
+ # # Alias for setproperty
133
153
setproperty(jlval, astToStr(fieldname), newval)
134
154
135
155
# Re-export
0 commit comments