Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c9db13a
Fix #355
yuin Jan 2, 2023
3f43d29
Fix #315
yuin Jan 2, 2023
6db614b
Migrate to Github Actions
yuin Jan 2, 2023
2d9b0c1
Migrate to Github Actions
yuin Jan 2, 2023
7f64c10
Migrate to Github Actions
yuin Jan 2, 2023
b4ade3d
Migrate to Github Actions
yuin Jan 2, 2023
804e438
Add 'goto' statement
yuin Jan 4, 2023
80c50bc
Update README.rst
yuin Jan 5, 2023
1a665bc
Update README.rst
yuin Jan 5, 2023
fa815b5
Fix #423
yuin Jan 22, 2023
410e9bd
Convert math params to number instead of failing with error
mdogan Sep 10, 2021
71163b6
Use O_TRUNC for files opened with "w"
waschik Feb 19, 2023
3467063
Add test for file writing
waschik Feb 19, 2023
d212719
Merge pull request #427 from waschik/write-trunc
yuin Apr 6, 2023
2a0d34e
fix: fix os.date("!*t", os.time()) will not get UTC date time issue
ttys3 Apr 12, 2023
63a49a4
Fix lua coroutine context leak
deflinhec May 19, 2023
8ee9c41
Merge pull request #438 from deflinhec/bugfix/coroutine-context-leak
yuin May 29, 2023
b60d3cf
Merge pull request #425 from mdogan/master
yuin May 29, 2023
e61dab4
test: rollback to use env default TZ variable
ttys3 May 30, 2023
d21032d
Revert "test: rollback to use env default TZ variable"
ttys3 May 30, 2023
2b3f02d
Merge pull request #433 from ttys3/fix-utc-date-format
yuin May 30, 2023
729b5db
Issue #452 : fix xpcall with error in error handler returns (nil, nil)
mzki Aug 12, 2023
6543bc9
add missing call of test() for #423
mzki Aug 12, 2023
1543e9d
popen: support nil in second argument
0x501D Oct 9, 2023
018eaa0
Merge pull request #460 from 0x501D/fix-gh-459
yuin Oct 14, 2023
293e22e
Merge branch 'master' into fix-xpcall-error-in-error-handler
mzki Oct 22, 2023
9d7d921
Merge pull request #453 from mzki/fix-xpcall-error-in-error-handler
yuin Nov 4, 2023
1e3d646
Inlining regstry.Set*
yuin Dec 2, 2023
1388221
Remove LValue.assert* functions.
yuin Dec 2, 2023
e1b215f
Re-add link to relocated gluasocket library; remove broken link to gl…
drauschenbach Dec 3, 2023
da9f439
Merge pull request #463 from Megalithic-LLC/updated-link-to-gluasocket
yuin Dec 5, 2023
5b5b27f
iolib: fix different behavior in read function
0x501D Sep 28, 2023
2348fd0
Merge pull request #456 from 0x501D/gh-455-fix-read
yuin Dec 12, 2023
182b189
Add github.com/PeerDB-io/gluabit32 to README.rst
serprex Mar 19, 2024
ed6d26a
Update README.rst
Root-lee Apr 30, 2024
c5204ed
doc: add awesome-gopher-lua
Root-lee May 3, 2024
b720190
fix compiler producing incorrect LOADNIL byte code
tul Jul 26, 2024
ec73447
fix: typo error for CompileLua example
warjiang Jul 30, 2024
b5e3b3f
Remove io/ioutil usages (deprecated since Go 1.16)
toqueteos Aug 1, 2024
91b4cff
Merge pull request #496 from tul/loadnil_fix
yuin Nov 9, 2024
7f73012
Merge pull request #498 from toqueteos/remove-deprecated-ioutil
yuin Nov 9, 2024
d1cb61e
Merge pull request #497 from warjiang/fix/typo-error
yuin Nov 9, 2024
48fb8d7
Merge pull request #488 from Root-lee/fix-README-format-error
yuin Nov 9, 2024
ccacf66
Merge pull request #483 from serprex/gluabit32
yuin Nov 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on: [push, pull_request]
name: test
jobs:
test:
strategy:
fail-fast: false
matrix:
go-version: [1.18.x, 1.19.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v1
- name: Run tests
run: ./_tools/go-inline *.go && go fmt . && go test -v ./... -covermode=count -coverprofile=coverage.out -coverpkg=$(go list ./... | sed 's/\n/,/g')
- name: Send coverage
if: "matrix.platform == 'ubuntu-latest'"
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
GO111MODULE=off go get github.com/mattn/goveralls
./_tools/go-inline *.go && go fmt .
$(go env GOPATH)/bin/goveralls -coverprofile=coverage.out -service=github
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

28 changes: 18 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
GopherLua: VM and compiler for Lua in Go.
===============================================================================

.. image:: https://godoc.org/github.com/yuin/gopher-lua?status.svg
:target: http://godoc.org/github.com/yuin/gopher-lua
.. image:: https://pkg.go.dev/badge/github.com/yuin/gopher-lua.svg
:target: https://pkg.go.dev/github.com/yuin/gopher-lua

.. image:: https://travis-ci.org/yuin/gopher-lua.svg
:target: https://travis-ci.org/yuin/gopher-lua
.. image:: https://github.com/yuin/gopher-lua/workflows/test/badge.svg?branch=master&event=push
:target: https://github.com/yuin/gopher-lua/actions?query=workflow:test

.. image:: https://coveralls.io/repos/yuin/gopher-lua/badge.svg
:target: https://coveralls.io/r/yuin/gopher-lua
.. image:: https://coveralls.io/repos/github/yuin/gopher-lua/badge.svg?branch=master
:target: https://coveralls.io/github/yuin/gopher-lua

.. image:: https://badges.gitter.im/Join%20Chat.svg
:alt: Join the chat at https://gitter.im/yuin/gopher-lua
Expand All @@ -19,7 +19,7 @@ GopherLua: VM and compiler for Lua in Go.
|


GopherLua is a Lua5.1 VM and compiler written in Go. GopherLua has a same goal
GopherLua is a Lua5.1(+ `goto` statement in Lua5.2) VM and compiler written in Go. GopherLua has a same goal
with Lua: **Be a scripting language with extensible semantics** . It provides
Go APIs that allow you to easily embed a scripting language to your Go host
programs.
Expand Down Expand Up @@ -595,7 +595,10 @@ Sharing byte code is safe as it is read only and cannot be altered by lua script

// Example shows how to share the compiled byte code from a lua script between multiple VMs.
func Example() {
codeToShare := CompileLua("mylua.lua")
codeToShare, err := CompileLua("mylua.lua")
if err != nil {
panic(err)
}
a := lua.NewState()
b := lua.NewState()
c := lua.NewState()
Expand Down Expand Up @@ -830,6 +833,8 @@ Miscellaneous notes
- ``file:setvbuf`` does not support a line buffering.
- Daylight saving time is not supported.
- GopherLua has a function to set an environment variable : ``os.setenv(name, value)``
- GopherLua support ``goto`` and ``::label::`` statement in Lua5.2.
- `goto` is a keyword and not a valid variable name.

----------------------------------------------------------------
Standalone interpreter
Expand All @@ -845,7 +850,7 @@ Lua has an interpreter called ``lua`` . GopherLua has an interpreter called ``gl
----------------------------------------------------------------
How to Contribute
----------------------------------------------------------------
See `Guidlines for contributors <https://github.com/yuin/gopher-lua/tree/master/.github/CONTRIBUTING.md>`_ .
See `Guidelines for contributors <https://github.com/yuin/gopher-lua/tree/master/.github/CONTRIBUTING.md>`_ .

----------------------------------------------------------------
Libraries for GopherLua
Expand All @@ -863,14 +868,17 @@ Libraries for GopherLua
- `gluaxmlpath <https://github.com/ailncode/gluaxmlpath>`_ : An xmlpath module for gopher-lua
- `gmoonscript <https://github.com/rucuriousyet/gmoonscript>`_ : Moonscript Compiler for the Gopher Lua VM
- `loguago <https://github.com/rucuriousyet/loguago>`_ : Zerolog wrapper for Gopher-Lua
- `gluabit32 <https://github.com/PeerDB-io/gluabit32>`_ : [Port of Lua 5.2 bit32](https://www.lua.org/manual/5.2/manual.html#6.7)
- `gluacrypto <https://github.com/tengattack/gluacrypto>`_ : A native Go implementation of crypto library for the GopherLua VM.
- `gluasql <https://github.com/tengattack/gluasql>`_ : A native Go implementation of SQL client for the GopherLua VM.
- `purr <https://github.com/leyafo/purr>`_ : A http mock testing tool.
- `vadv/gopher-lua-libs <https://github.com/vadv/gopher-lua-libs>`_ : Some usefull libraries for GopherLua VM.
- `gluaperiphery <https://github.com/BixData/gluaperiphery>`_ : A periphery library for the GopherLua VM (GPIO, SPI, I2C, MMIO, and Serial peripheral I/O for Linux).
- `gluasocket <https://gitlab.com/megalithic-llc/gluasocket>`_ : A native Go implementation of LuaSocket for the GopherLua VM.
- `glua-async <https://github.com/CuberL/glua-async>`_ : An async/await implement for gopher-lua.
- `gopherlua-debugger <https://github.com/edolphin-ydf/gopherlua-debugger>`_ : A debugger for gopher-lua
- `gluamahonia <https://github.com/super1207/gluamahonia>`_ : An encoding converter for gopher-lua
- `awesome-gopher-lua <https://github.com/Root-lee/awesome-gopher-lua>`_ : Collections of awesome libraries for GopherLua.

----------------------------------------------------------------
Donation
----------------------------------------------------------------
Expand Down
173 changes: 173 additions & 0 deletions _glua-tests/goto.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
local function errmsg (code, m)
local st, msg = loadstring(code)
assert(not st and string.find(msg, m))
end

-- cannot see label inside block
errmsg([[ goto l1; do ::l1:: end ]], "label 'l1'")
errmsg([[ do ::l1:: end goto l1; ]], "label 'l1'")

-- repeated label
errmsg([[ ::l1:: ::l1:: ]], "label 'l1'")


-- undefined label
errmsg([[ goto l1; local aa ::l1:: ::l2:: print(3) ]], "local 'aa'")

-- jumping over variable definition
errmsg([[
do local bb, cc; goto l1; end
local aa
::l1:: print(3)
]], "local 'aa'")

-- jumping into a block
errmsg([[ do ::l1:: end goto l1 ]], "label 'l1'")
errmsg([[ goto l1 do ::l1:: end ]], "label 'l1'")

-- cannot continue a repeat-until with variables
errmsg([[
repeat
if x then goto cont end
local xuxu = 10
::cont::
until xuxu < x
]], "local 'xuxu'")

-- simple gotos
local x
do
local y = 12
goto l1
::l2:: x = x + 1; goto l3
::l1:: x = y; goto l2
end
::l3:: ::l3_1:: assert(x == 13)


-- long labels
do
local prog = [[
do
local a = 1
goto l%sa; a = a + 1
::l%sa:: a = a + 10
goto l%sb; a = a + 2
::l%sb:: a = a + 20
return a
end
]]
local label = string.rep("0123456789", 40)
prog = string.format(prog, label, label, label, label)
assert(assert(loadstring(prog))() == 31)
end

-- goto to correct label when nested
do goto l3; ::l3:: end -- does not loop jumping to previous label 'l3'

-- ok to jump over local dec. to end of block
do
goto l1
local a = 23
x = a
::l1::;
end

while true do
goto l4
goto l1 -- ok to jump over local dec. to end of block
goto l1 -- multiple uses of same label
local x = 45
::l1:: ;;;
end
::l4:: assert(x == 13)

if print then
goto l1 -- ok to jump over local dec. to end of block
error("should not be here")
goto l2 -- ok to jump over local dec. to end of block
local x
::l1:: ; ::l2:: ;;
else end

-- to repeat a label in a different function is OK
local function foo ()
local a = {}
goto l3
::l1:: a[#a + 1] = 1; goto l2;
::l2:: a[#a + 1] = 2; goto l5;
::l3::
::l3a:: a[#a + 1] = 3; goto l1;
::l4:: a[#a + 1] = 4; goto l6;
::l5:: a[#a + 1] = 5; goto l4;
::l6:: assert(a[1] == 3 and a[2] == 1 and a[3] == 2 and
a[4] == 5 and a[5] == 4)
if not a[6] then a[6] = true; goto l3a end -- do it twice
end

::l6:: foo()



--------------------------------------------------------------------------------
-- testing closing of upvalues

local function foo ()
local a = {}
do
local i = 1
local k = 0
a[0] = function (y) k = y end
::l1:: do
local x
if i > 2 then goto l2 end
a[i] = function (y) if y then x = y else return x + k end end
i = i + 1
goto l1
end
end
::l2:: return a
end

local a = foo()
a[1](10); a[2](20)
assert(a[1]() == 10 and a[2]() == 20 and a[3] == nil)
a[0](13)
assert(a[1]() == 23 and a[2]() == 33)

--------------------------------------------------------------------------------
-- testing if x goto optimizations

local function testG (a)
if a == 1 then
goto l1
error("should never be here!")
elseif a == 2 then goto l2
elseif a == 3 then goto l3
elseif a == 4 then
goto l1 -- go to inside the block
error("should never be here!")
::l1:: a = a + 1 -- must go to 'if' end
else
goto l4
::l4a:: a = a * 2; goto l4b
error("should never be here!")
::l4:: goto l4a
error("should never be here!")
::l4b::
end
do return a end
::l2:: do return "2" end
::l3:: do return "3" end
::l1:: return "1"
end

assert(testG(1) == "1")
assert(testG(2) == "2")
assert(testG(3) == "3")
assert(testG(4) == 5)
assert(testG(5) == 10)
--------------------------------------------------------------------------------


print'OK'
86 changes: 86 additions & 0 deletions _glua-tests/issues.lua
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,89 @@ function test()
assert(2 % 2 == 0)
end
test()

-- issue #355
function test()
local x = "valid"
assert(x == "valid")
assert(zzz == nil)
x = zzz and "not-valid" or x
assert(x == "valid")
end
test()

function test()
local x = "valid"
local z = nil
assert(x == "valid")
assert(z == nil)
x = z and "not-valid" or x
assert(x == "valid")
end
test()

function test()
local x = "valid"
assert(x == "valid")
assert(zzz == nil)
x = zzz and "not-valid" or "still " .. x
assert(x == "still valid")
end
test()

-- issue #315
function test()
local a = {}
local d = 'e'
local f = 1

f, a.d = f, d

assert(f..", "..a.d == "1, e")
end
test()

-- issue #423
function test()
local a, b, c = "1", "3", "1"
a, b, c= tonumber(a), tonumber(b) or a, tonumber(c)
assert(a == 1)
assert(type(a) == "number")
assert(b == 3)
assert(type(b) == "number")
assert(c == 1)
assert(type(c) == "number")
end
test()

-- issue #452
function test()
local ok, msg = pcall(function()
local ok, msg = xpcall(function() error("fn") end, function(err) error("handler") end)
assert(not ok and msg)
error("expected to reach this.")
end)
assert(not ok)
end
test()

-- issue #455
function test()
local path = "."
local fd, _, code = io.open(path, "r")
assert(fd ~= nil)
local _, _, ecode = fd:read(1)
assert(ecode == 1)
end
test()

-- issue #459
function test()
local a, b = io.popen("ls", nil)
assert(a)
assert(b == nil)
local a, b = io.popen("ls", nil, nil)
assert(a)
assert(b == nil)
end
test()
Loading