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

I think it is a bug #9

Open
Freakwill opened this issue Apr 2, 2019 · 1 comment
Open

I think it is a bug #9

Freakwill opened this issue Apr 2, 2019 · 1 comment

Comments

@Freakwill
Copy link

Freakwill commented Apr 2, 2019

Let's see the following code. whenever a variable is nil, it will be a function if import sh.

require('sh')
print(type(x), type(nil))  -- function, nil
x = nil
print(type(x))   -- function, but x is set to be nil
t = {}
x = 'hello'
z = t[x]
print(type(t[x]), type(z))  -- nil, function, but z should be nil as usual.

I forgive the first one, since x may be set to be a function by sh, but how to explain next two?

@mnemnion
Copy link

mnemnion commented Dec 8, 2019

This is the ordinary logic of Lua; setting a variable to nil is the same thing as never setting it in the first place.

So there's no difference between z = nil (and z = t[x] on an empty t is just a fancy way of saying z = nil) and not setting z in the first place. In both cases, the failed lookup on _G triggers the __newindex patch, causing a shell function to be returned.

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

2 participants