fengari-web
fengari-web copied to clipboard
Null value is not accepted as null actually
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
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