-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MultiReturn support #87
base: main
Are you sure you want to change the base?
Changes from all commits
d536b64
e3f0ef7
eb09314
0feffda
d8494e5
6d816a0
84601e8
3186b18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,13 +168,14 @@ describe('Engine', () => { | |
expect(sum(10, 50)).to.be.equal(60) | ||
}) | ||
|
||
// TEST OFTEN BREAKS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just having a think about this PR and I've never seen this test fail before this change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure that PR breake this test. it breaks from time to time. sometimes if more or less then expected. |
||
it('scheduled lua calls should succeed', async () => { | ||
const engine = await getEngine() | ||
engine.global.set('setInterval', setInterval) | ||
|
||
await engine.doString(` | ||
test = "" | ||
setInterval(function() | ||
setInterval(function () | ||
Comment on lines
-177
to
+178
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it's not related to the PR, don't change it |
||
test = test .. "i" | ||
end, 1) | ||
`) | ||
|
@@ -238,6 +239,54 @@ describe('Engine', () => { | |
expect(returns.at(-1)).to.be.a('function') | ||
}) | ||
|
||
it('doString with multiple returns should succeed', async () => { | ||
const engine = await getEngine() | ||
|
||
const returns = await engine.doString(` | ||
return 1, x, y, "Hello World", {}, function() end, {1,2,3}, {a = 1, b = 2, c = 3}; | ||
`) | ||
|
||
expect(returns).to.be.a('array') | ||
expect(returns).to.have.length(8) | ||
expect(returns[5]).to.be.a('function') | ||
expect(returns[6]).to.be.a('array') | ||
expect(returns[7]).to.be.a('object') | ||
}) | ||
|
||
it('call lua function with multiple returns should succeed', async () => { | ||
const engine = await getEngine() | ||
|
||
const fn = await engine.doString(` | ||
return function (x, y) | ||
return 1, x, y, function () end, {1,2,3}, {a = 1, b = 2}; | ||
end | ||
`) | ||
|
||
expect(fn).to.be.a('function') | ||
|
||
const returns = fn(4, 5) | ||
const [func, arr, obj] = returns.slice(3) | ||
expect(returns).to.have.length(6) | ||
expect(func).to.be.a('function') | ||
expect(arr).to.be.a('array') | ||
expect(obj).to.be.a('object') | ||
}) | ||
|
||
it('call lua function with single returns array should succeed', async () => { | ||
const engine = await getEngine() | ||
|
||
const fn = await engine.doString(` | ||
return function (a, b, c) | ||
return {a, b, c}; | ||
end | ||
`) | ||
|
||
expect(fn).to.be.a('function') | ||
const array = fn(3, 4, 5) | ||
expect(array).to.be.an('array') | ||
expect(array).to.have.length(3) | ||
}) | ||
|
||
it('get a lua thread should succeed', async () => { | ||
const engine = await getEngine() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ describe('Filesystem', () => { | |
await factory.mountFile('yolo/sofancy/test.lua', 'return 42') | ||
const engine = await factory.createEngine() | ||
|
||
const value = await engine.doString('return require("yolo/sofancy/test")') | ||
// second parameter is path to module | ||
const [value] = await engine.doString('return require("yolo/sofancy/test")') | ||
|
||
expect(value).to.be.equal(42) | ||
}) | ||
|
@@ -27,7 +28,8 @@ describe('Filesystem', () => { | |
await factory.mountFile('hello/init.lua', 'return 42') | ||
const engine = await factory.createEngine() | ||
|
||
const value = await engine.doString('return require("hello")') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary changes interface |
||
// second parameter is path to module | ||
const [value] = await engine.doString('return require("hello")') | ||
|
||
expect(value).to.be.equal(42) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary change, and dont related with PR