fengari-web icon indicating copy to clipboard operation
fengari-web copied to clipboard

Null value is not accepted as null actually

Open yangol-oleksiy opened this issue 3 years ago • 1 comments

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

yangol-oleksiy avatar Apr 02 '22 19:04 yangol-oleksiy

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

daurnimator avatar Apr 20 '22 13:04 daurnimator