Skip to content
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

Functions with one table argument #4

Open
echo-Mike opened this issue Jan 12, 2017 · 0 comments
Open

Functions with one table argument #4

echo-Mike opened this issue Jan 12, 2017 · 0 comments

Comments

@echo-Mike
Copy link

If function defined like:

function foo(t)
    local name = t.name or "other"
    local num = t.num or 1
--Stuf
end

Then it will raise an error when called like foo()
Error messege in tabletop interpreter:

stdin:1: attempt to index local 't' (a nil value)
stack traceback:
stdin:1: in function 'foo'
stdin:1: in main chunk
[C]: ?

Same will occur in Codea.
In order to fix this problem you need to use next function definition:

function foo(t)
    local t = t or {}
    local name = t.name or "other"
    local num = t.num or 1
--Stuf
end

This problem is eliminated if all functions called only like foo{}
Where it is occur: many places in project in functions definitions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant