daurnimator / lua.vm.js

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

Best way to debug? #23

Closed fpsvogel closed 9 years ago

fpsvogel commented 9 years ago

Hi, I'm having trouble running a lua script under the VM. I've successfully tested the VM with simple code, and my script works running it normally with lua. I've escaped all single-quotes in the script with \x27, and I made sure the string of code is all in one piece. Am I missing something, any rules of thumb? The reason I'm not posting any code specifically is that it's quite a long script, but I can pastebin it if you'd like. Thanks.

LunarLanding commented 9 years ago

You can use mobdebug via websockets. See https://github.com/LunarLanding/mobdebug_js On Jan 10, 2015 1:29 AM, "fps-vogel" notifications@github.com wrote:

Hi,

I'm having trouble running a lua script under the VM. I've successfully tested the VM with simple code, and my script works running it normally with lua. I escaped all single-quotes in the script with \x27, and I made sure the string of code is all in one piece. Am I missing something, any rules of thumb? The reason I'm not posting any code specifically is that it's quite a long script, but I can pastebin it if you'd like. Thanks.

— Reply to this email directly or view it on GitHub https://github.com/kripken/lua.vm.js/issues/23.

daurnimator commented 9 years ago

There should be an error message. What is it?

fpsvogel commented 9 years ago

I'm a bit confused as to how to set up mobdebug. I've got the modules, but where does my script fit in? Should I paste it in main.lua? The other step I don't understand is to "start the debug server", since that sounds like it's not the same as (and comes after) "start the mobdebug server" which is explained on the mobdebug page. Sorry for my ignorance.

fpsvogel commented 9 years ago

Also, when I try to start the mobdebug server with lua -e "require('mobdebug').listen()", I get the error ".\socket.lua:4: attempt to index global 'js' (a nil value)". I'm probably missing something obvious...

LunarLanding commented 9 years ago

By starting the server I mean opening mobdebug(the ide). There should be a button in the debug pane for starting the server. As for js not being defined. That's very weird. Maybe you could try the example provided in the mobdebug_js repository? If you have any more doubts about setting up the remote debugger, maybe it would be best to continue them in mobdebug_js repository.

I'm a bit confused as to how to set up mobdebug. I've got the modules, but where does my script fit in? Should I paste it in main.lua? The other step I don't understand is to "start the debug server". Sorry for my ignorance.

— Reply to this email directly or view it on GitHub https://github.com/kripken/lua.vm.js/issues/23#issuecomment-69434480.

fpsvogel commented 9 years ago

I haven't gotten mobdebug running, but I did figure out what was wrong with my Lua code and it is now running fine under the VM. I forgot to escape backslashes like I escaped single-quotes, and the VM doesn't like comments because when I took them out it ran fine. So now I can fully appreciate how great this VM is. Thanks!

daurnimator commented 9 years ago

the VM doesn't like comments because when I took them out it ran fine.

It should be fine with comments. Do you have a small sample?

fpsvogel commented 9 years ago
var rets = L.execute('return "testing, testing" -- comment');
console.log(rets[0]);

works as expected, but the following outputs "undefined":

var rets = L.execute(commenttest);
console.log(rets[0]);
...
var commenttest = [
    '-- comment \
    return "testing, testing" '
]
daurnimator commented 9 years ago

the following outputs "undefined":

var rets = L.execute(commenttest); console.log(rets[0]); ... var commenttest = [ '-- comment \ return "testing, testing" ' ]

Preceding a newline with '\' only lets you write a string over multiple lines in javascript, a newline is not actually present in the string. See for yourself by running:

console.log('-- comment \
return "testing, testing" ')

As such, all you're sending to lua is the string -- comment return "testing, testing", which is a single line (that is a comment)

fpsvogel commented 9 years ago

Got it, thanks!