summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-21 22:48:29 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-22 00:50:30 +1000
commit50323a75a96cfa095c1f968dd001b0f7107a722b (patch)
tree483be766d1dcba496b7aa205da8c972fc02c53fd
parentcc3e3c93585d81304954131a9a3982f0786426b7 (diff)
downloadfengari-50323a75a96cfa095c1f968dd001b0f7107a722b.tar.gz
fengari-50323a75a96cfa095c1f968dd001b0f7107a722b.tar.bz2
fengari-50323a75a96cfa095c1f968dd001b0f7107a722b.zip
src/lbaselib.js: Implement argument checking in collectgarbage
-rw-r--r--src/lbaselib.js11
-rw-r--r--tests/test-suite/events.js6
-rw-r--r--tests/test-suite/nextvar.js2
3 files changed, 14 insertions, 5 deletions
diff --git a/src/lbaselib.js b/src/lbaselib.js
index 8f0827e..bffe5a6 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -85,6 +85,15 @@ const luaB_rawset = function(L) {
return 1;
};
+const opts = ["stop", "restart", "collect",
+"count", "step", "setpause", "setstepmul",
+"isrunning"].map((e) => lua.to_luastring(e));
+const luaB_collectgarbage = function(L) {
+ lauxlib.luaL_checkoption(L, 1, lua.to_luastring("collect"), opts);
+ lauxlib.luaL_checkinteger(L, 2);
+ lauxlib.luaL_error(L, lua.to_luastring("lua_gc not implemented"));
+};
+
const luaB_type = function(L) {
let t = lua.lua_type(L, 1);
lauxlib.luaL_argcheck(L, t !== lua.LUA_TNONE, 1, lua.to_luastring("value expected", true));
@@ -308,8 +317,8 @@ const luaB_load = function(L) {
};
const base_funcs = {
- "collectgarbage": function () { return 0; },
"assert": luaB_assert,
+ "collectgarbage": luaB_collectgarbage,
"error": luaB_error,
"getmetatable": luaB_getmetatable,
"ipairs": luaB_ipairs,
diff --git a/tests/test-suite/events.js b/tests/test-suite/events.js
index 14391f2..d5ed5ae 100644
--- a/tests/test-suite/events.js
+++ b/tests/test-suite/events.js
@@ -17,7 +17,7 @@ test("[test-suite] events: testing metatable", function (t) {
_ENV = setmetatable({}, {__index=_G})
- collectgarbage()
+ --collectgarbage()
X = X+10
assert(X == 30 and _G.X == 20)
@@ -57,7 +57,7 @@ test("[test-suite] events: testing metatable", function (t) {
a.parent = {z=25, x=12, [4] = 24}
assert(a[1] == 10 and a.z == 28 and a[4] == 27 and a.x == "10")
- collectgarbage()
+ --collectgarbage()
a = setmetatable({}, t)
function f(t, i, v) rawset(t, i, v-3) end
@@ -244,7 +244,7 @@ test("[test-suite] events: test comparison", function (t) {
let luaCode = `
t = {}
t.__lt = function (a,b,c)
- collectgarbage()
+ --collectgarbage()
assert(c == nil)
if type(a) == 'table' then a = a.x end
if type(b) == 'table' then b = b.x end
diff --git a/tests/test-suite/nextvar.js b/tests/test-suite/nextvar.js
index 6cf7c74..d119d97 100644
--- a/tests/test-suite/nextvar.js
+++ b/tests/test-suite/nextvar.js
@@ -658,7 +658,7 @@ test("[test-suite] nextvar: erasing values", function (t) {
n = n+1
assert(t[k] == v)
t[k] = nil
- collectgarbage()
+ --collectgarbage()
assert(t[k] == nil)
end
assert(n == 5)