File tree Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Expand file tree Collapse file tree 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.
1919|
2020
2121
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
2324with Lua: **Be a scripting language with extensible semantics ** . It provides
2425Go APIs that allow you to easily embed a scripting language to your Go host
2526programs.
@@ -835,6 +836,7 @@ Miscellaneous notes
835836- GopherLua has a function to set an environment variable : ``os.setenv(name, value) ``
836837- GopherLua support ``goto `` and ``::label:: `` statement in Lua5.2.
837838 - `goto ` is a keyword and not a valid variable name.
839+ - GopherLua respects the `__index ` metamethod in `ipairs ` as in Lua 5.3.
838840
839841----------------------------------------------------------------
840842Standalone interpreter
Original file line number Diff line number Diff line change @@ -15,6 +15,15 @@ assert(#tbl == 10)
1515setmetatable (tbl , nil )
1616assert (# tbl == 3 )
1717
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+
1827local ok , msg = pcall (function ()
1928 return 1 < " hoge"
2029end )
Original file line number Diff line number Diff line change @@ -133,16 +133,17 @@ func baseGetMetatable(L *LState) int {
133133}
134134
135135func ipairsaux (L * LState ) int {
136- tb := L .CheckTable (1 )
136+ tb := L .Get (1 )
137137 i := L .CheckInt (2 )
138138 i ++
139- v := tb .RawGetInt (i )
139+ li := LNumber (i )
140+ v := L .getField (tb , li )
140141 if v == LNil {
141142 return 0
142143 } else {
143144 L .Pop (1 )
144- L .Push (LNumber ( i ) )
145- L .Push (LNumber ( i ) )
145+ L .Push (li )
146+ L .Push (li )
146147 L .Push (v )
147148 return 2
148149 }
You can’t perform that action at this time.
0 commit comments