daurnimator / lua.vm.js

The project is superceded by Fengari. See https://fengari.io/
MIT License
835 stars 101 forks source link

Testing null value #41

Closed MangelMaxime closed 8 years ago

MangelMaxime commented 8 years ago

Hello guys, I am trying to test if a node exist or not.

local d = js.global.document:getElementById("test")
print(d) -- return null
if d then
  print(d.innerHTML) -- return Uncaught Lua.Error: TypeError: Cannot read property 'innerHTML' of null
end

In my page the id test doesn't exist but the if is always executed. How do you check for null and/or undefined value from lua code ?

daurnimator commented 8 years ago

How do you check for null and/or undefined value from lua code ?

null you need to compare to js.null.

undefined is the same as nil

MangelMaxime commented 8 years ago

Thanks again for your help.

I have others interrogations about the tables etc. Is there a better way to question/discuss then issue because it's potentially not an issue.

Or is there any good samples of implementation or documentation ?

daurnimator commented 8 years ago

I have others interrogations about the tables etc. Is there a better way to question/discuss then issue because it's potentially not an issue.

I'm happy to answer questions via github issues; this way I can refer others to them.

You can also find me on irc with the same username (on freenode and oftc) if you have a quick question.

Or is there any good samples of implementation or documentation ?

Sorry we're a bit light on documentation. I'm not happy with how lua.vm.js leaks memory via proxys; and solving it may require a full overhaul.