-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
load function fails with nil args #91
Comments
How were you calling this? |
Great question! I'm actually using luerl with Fennel, which is a small compiler which targets Lua: https://github.com/bakpakin/Fennel/blob/master/fennel.lua#L64 I have been investigating some of the less mainstream Lua implementations to see if I could uncover any bugs with Fennel. But I believe Erlang semantics might be leaking here--Lua semantics would dictate that there is basically no way for a function to tell the difference between being called like That appears to not be the case here, at least with |
So This should only be a problem with functions in the standard libraries and not in functions defined in Lua. |
If they are given they must be strings otherwise you get an argument error
I think this is where the problem lies with this statement. In Erlang
it's impossible to have the 3rd argument be provided if the second
isn't, but in Lua this is a perfectly normal occurrence. Lua is
different from most lisps in that nil actually consistently means the
absence of a value, so "when this value is not given" means when it's nil.
I think the lower-arity versions just need to be wrappers that call the
max-arity versions filling out the args with nils, and the max-arity
just needs to expect that any optional argument can be nil.
Is calling load("return 1+1", nil, "bt") legal? The manual doesn't say.
Depending on your interpretation of the phrasing in the manual, I could
see how this could be considered technically undefined, but of the 4
other Lua implementations I've tried they have all supported it.
|
How would it be interpreted? One way would be that all the |
One way would be that all the nil arguments get their default value.
Oh, yes that's exactly what I meant; sorry, I realize I wasn't clear about that.
It should be a universal rule for Lua functions with optional arguments; I can't think of any exceptions.
|
I will have a go and try to fix it. There is one limitation with load which is a bit more difficult to fix and that is that it currently only accepts a file name as first and not a function. This is more difficult to fix as calling lua functions from within erlang is a bit more tricky. We shall see if I can fix that as well. |
I will gradually upgrade the internal functions. If you come across where an explicit nil as an argument does not mean use the default then let me know. |
That sounds good; thanks!
|
This code, as you might expect, prints "2":
However, this code fails, even though it should work exactly the same:
The text was updated successfully, but these errors were encountered: