4 ms·
I tried it on embedded. Wasn’t happening for me. Eventually moved to mJS a similar JS engine for C. Eventually dumped that and moved to Lua. Part of the issue
by SlowRobotAhead 7y ago
I tried it on embedded. Wasn’t happening for me. Eventually moved to mJS a similar JS engine for C. Eventually dumped that and moved to Lua.
Part of the issue is I needed a scripting engine, but I didn’t NEED JS. It was also a pain that the code/script was in ASCII which had to go to base64 and none of this was as good as compiled for efficiency.
I wasn’t going to let users run their own code, so that’s probably a big reason people use this.
- tyingq 7y agoTCL would have been another choice. Still used by quite a few commercial entities as an embedded scripting language.
- marktangotango 7y agoBigIP F5 irules shudder.
- SlowRobotAhead 7y agoI need FFI (foreign function interface) to fall C functions from the scripting language. My glance into TCL did not turn up a native FFI.
- tyingq 7y agoAhh. It has good support for extensions written in C. But no scriptable ffi where you can dynamically load libraries and run functions.
- blacksqr 7y agoFfidl (https://prs-de.github.io/ffidl/ https://prs-de.github.io/ffidl/) is the standard library extension for Tcl to make use of FFI. Tcl's philosophy is to keep the core lean and extend functionality via loadable libraries.
- SlowRobotAhead 7y agoI'll take a look, thanks. EDIT: Not too bad actually. I'll take a look and compare to Lua. I'm not ::crazy::about:TCL's syntax, but it's not that bad.
- vortico 7y agoWhat issues with Duktape led to you using Lua? I've used both Duktape and Lua for years for non-embedded (desktop), and they seem very similar in requirements, so I would have guessed both would be a similar experience in microcontrollers.
- SlowRobotAhead 7y agoI have about 24k flash I could use. Lua came in smaller, ended up using less ram. And, the code for Lua is natively binary which was a plus.
- vortico 7y agoAh yes, Duktape is around 100KiB.
- sanxiyn 7y agoFYI: mJS is most likely https://github.com/cesanta/mjs https://github.com/cesanta/mjs. It can be hard to search for because .mjs is also a file extension for JS modules.
- SlowRobotAhead 7y agoYes, you’re right. Also, super-annoyingly I think there is another entirely separate JS interpreter called mJS. Someone didn’t search before giving their code a name.
- sanxiyn 7y agoDuktape also has Lua-like bytecode. Maybe it isn't as good, but it is not the case that Duktape lacks compiled form.
- pb82 7y agoOne difference seems to be that in Duktape you can only generate bytecode for one function at a time (duk_dump_function) while in Lua you can just load your whole script and dump it as bytecode (lua_dump). Sure, you can wrap your code in a self executing function in JS to get around this. But Lua looks to be somewhat more convenient for this use case.