fengari-lua / fengari-web

Provides everything you need to run Fengari in the browser.
MIT License
250 stars 19 forks source link

Null value is not accepted as null actually #52

Closed yangol-oleksiy closed 1 year ago

yangol-oleksiy commented 2 years ago

I have sample code and very strange (wrong ?) results it outputs

local out = document:getElementById("out")
out.onclick = nil

js.global.console:log('property value')
js.global.console:log(out.onclick)
js.global.console:log('property type')
js.global.console:log(type(out.onclick))
js.global.console:log('null type')
js.global.console:log(type(null))
js.global.console:log('nil type')
js.global.console:log(type(nil))

output is

property value
null
property type
userdata
null type
nil
nil type
nil

So, why I set out.onclick to nil and its value is null but its type is userdata ?

Reproduced on Google Chrome 99.0.4844.84

daurnimator commented 2 years ago
js.global.console:log(type(null))

null is not a keyword in lua, you're just looking for a global variable called null, which happens to be nil at the time.

Likely you want js.null https://github.com/fengari-lua/fengari-interop#null