Posted 03 March 2018 - 04:02 PM
I'm working on a stream api for a more stream-based programming style and now I am stuck on a weird error: I'm getting a error in computercraft, but in normal lua not.
First I thought I had a error in my code, this is why I asked at StackOverflow for help, but it turns out not to be a Lua error.
Basically as soon as I call the method stream with any table as argument - for example: stream({}), stream({1,2,3}) or stream({a=1,b=2,c=3}) - I'm getting the error:
attempt to call table
Here is a minimal example to try it:
Also here is the full source.
Can anyone help me? Or is this a bug in ComputerCraft or LuaJ?
First I thought I had a error in my code, this is why I asked at StackOverflow for help, but it turns out not to be a Lua error.
Basically as soon as I call the method stream with any table as argument - for example: stream({}), stream({1,2,3}) or stream({a=1,b=2,c=3}) - I'm getting the error:
attempt to call table
Here is a minimal example to try it:
function stream(input)
-- ...
local function _count()
local count = 0
for k, v in pairs(input._data) do
count = count + 1
end
return count
end
local function _foreach(func)
for k, v in pairs(input._data) do
func(v, k)
end
end
-- ...
local function _stream(input)
local result = {
_data = input._data or input,
-- ...
count = _count,
foreach = _foreach,
-- ...
}
return result
end
if input == nil then
error("input must be of type table, but was nil")
elseif type(input) ~= "table" then
error("input must be of type table, but was a "..type(input)..": "..input)
end
input = _stream(input)
return input
end
-- This fails in CC but not in Lua
stream({})
stream({1,2,3})
stream({a=1,b=2,c=3})
Also here is the full source.
Can anyone help me? Or is this a bug in ComputerCraft or LuaJ?