gamesys / moonshine

A lightweight Lua VM for the browser
http://moonshinejs.org
MIT License
501 stars 35 forks source link

DOM element can't call function? #16

Closed CerfurMark closed 10 years ago

CerfurMark commented 10 years ago

Hello, I am using your fabulous vm with the DOM extension. Can you tell me if this code should work or what I'm doing wrong? I am trying to create web page formatting with just Lua commands.

 para = window.document:createElement("p") 
  para:createTextNode("abc") 

Unfortunately, I get this error:

Uncaught Moonshine run-time error: Attempt to call non-function @dv.lua [./null:8]

Thank you.

paulcuth commented 10 years ago

Hi,

Thanks for using Moonshine. createTextNode() is only available on the document object, so you can't do that in JavaScript either. Try the following:

para = window.document:createElement "p"
text = window.document:createTextNode "abc"

para:appendChild(text)

Regards, Paul.

CerfurMark commented 10 years ago

Wow, now that it's morning, it's obvious. I should have gone to bed before posting! Thank you for your help. Mark

paulcuth commented 10 years ago

No problem. I suspected that it might be something like that. :) Give me a shout if you have any other problems and let me know how it turns out.

Paul.