File tree 3 files changed +17
-5
lines changed
3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,8 @@ GopherLua: VM and compiler for Lua in Go.
19
19
|
20
20
21
21
22
- GopherLua is a Lua5.1(+ `goto ` statement in Lua5.2) VM and compiler written in Go. GopherLua has a same goal
22
+ GopherLua is a Lua 5.1 (+ `goto ` statement from Lua 5.2 and `ipairs ` as in Lua 5.3)
23
+ VM and compiler written in Go. GopherLua has a same goal
23
24
with Lua: **Be a scripting language with extensible semantics ** . It provides
24
25
Go APIs that allow you to easily embed a scripting language to your Go host
25
26
programs.
@@ -835,6 +836,7 @@ Miscellaneous notes
835
836
- GopherLua has a function to set an environment variable : ``os.setenv(name, value) ``
836
837
- GopherLua support ``goto `` and ``::label:: `` statement in Lua5.2.
837
838
- `goto ` is a keyword and not a valid variable name.
839
+ - GopherLua respects the `__index ` metamethod in `ipairs ` as in Lua 5.3.
838
840
839
841
----------------------------------------------------------------
840
842
Standalone interpreter
Original file line number Diff line number Diff line change @@ -15,6 +15,15 @@ assert(#tbl == 10)
15
15
setmetatable (tbl , nil )
16
16
assert (# tbl == 3 )
17
17
18
+ setmetatable (tbl , {__index = function (t , i )
19
+ return i <= 5 and - i or nil
20
+ end })
21
+ local s = 0
22
+ for _ , x in ipairs (tbl ) do
23
+ s = s + x
24
+ end
25
+ assert (s == - 3 ) -- == 1+2+3-4-5
26
+
18
27
local ok , msg = pcall (function ()
19
28
return 1 < " hoge"
20
29
end )
Original file line number Diff line number Diff line change @@ -133,16 +133,17 @@ func baseGetMetatable(L *LState) int {
133
133
}
134
134
135
135
func ipairsaux (L * LState ) int {
136
- tb := L .CheckTable (1 )
136
+ tb := L .Get (1 )
137
137
i := L .CheckInt (2 )
138
138
i ++
139
- v := tb .RawGetInt (i )
139
+ li := LNumber (i )
140
+ v := L .getField (tb , li )
140
141
if v == LNil {
141
142
return 0
142
143
} else {
143
144
L .Pop (1 )
144
- L .Push (LNumber ( i ) )
145
- L .Push (LNumber ( i ) )
145
+ L .Push (li )
146
+ L .Push (li )
146
147
L .Push (v )
147
148
return 2
148
149
}
You can’t perform that action at this time.
0 commit comments