4 ms·
Yeah I actually don't think Lua is great for those things, tbh. Lua is not a good tool for manipulating JSON--JavaScript is probably sensible for that (it is Ja
by nikki93 6y ago
Yeah I actually don't think Lua is great for those things, tbh. Lua is not a good tool for manipulating JSON--JavaScript is probably sensible for that (it is JavaScript's object format, after all). And yeah I don't think it's good to use a bunch of external libraries in Lua, since as you say there's not a common ground for how data is organized. The libraries I rely on are are more native integration things like lpeg, luasocket, luasec, love2d, ... They've all been quite good. And yeah you keep saying 'sentinels' in quotes but honestly it's worked fine when using lua-cjson. There's always an impedance mismatch between JavaScript's object format and Lua's though. Lua also allows non-string keys which are great in Lua but not a thing in JavaScript, and in practice I've found the array/object-table mismatch more problematic than `nil`/`null` and so on.
I've mostly applied Lua for embedding in game engines, and to that end there's nothing that comes close, short of rolling your own VM that's exactly built the way you want. The main way to use it I think is to embed it somewhere and build up the set of utilities / libraries that you need to script over. But yeah it's not great for API glue code bc. APIs tend to bias toward JavaScript / JSON and other ways of doing things.
- aasasd 6y agoWell, my lament in the first place is that Lua could be a good and fast general-purpose scripting language. Instead, I can have ‘good’ but then I'll have to sit around twiddling thumbs while Python or JS start up. Especially Fennel runs circles around ClojureScript in terms of toolchain and build-cycle lightness. JSON is pretty non-specific to JavaScript, which is probably a part of its popularity. And it's not the only serialization format. Null works about the same way in the majority of popular languages—so you're bound to need it for interoperability if you go outside C. By libraries, I mean Lua libs like Penlight. Once you touch functional programming and function composition, you want structures to be preserved as they are, unless explicitly mangled. > And yeah you keep saying 'sentinels' in quotes It's because I haven't seen that notion before, at least under this name.
- nikki93 6y agoHave you tried lua-cjson, out of curiosity? They use a cjson.null (or something like that) value for nulls in JSON. But yeah agree with what you've said in general, if I had to do some API JSON manipulation Lua isn't what I'd jump to, even though I'm pretty familiar with it. Do Python or JS actually take that much longer to start up for a script? Node starts up pretty quickly on my system.
- aasasd 6y agoNow that I think of it, cjson.null might be workable even with data-transformation libraries, since it's some Lua meta-voodoo-value that can't come in the input from other systems. But then, of course, there's the problem that other data-exchange libs invent their own voodoo-values for null, like ngx.null. Precisely because they need it for actual integration use-cases. As for the performance, I happen to use an underpowered machine, which is how I discovered the drastic difference with Lua. However, performance still matters beyond just ‘pretty quickly’ if you consider desktop software, especially productivity software—which has to be snappy. Scripting your productivity software is a textbook case for dynamic languages, and almost the exact niche for Lua. Even on my machine, there was a moment when I had to make sure that Alfred actually called my Lua script—because the results popped up immediately (despite going through the command-line interpreter, not Luajit). Meanwhile, people are making productivity software with Electron or Python, which to me verges on ridiculous.
- nikki93 6y agoYeah, I definitely care about performance more in that tradeoff. In my experience when performance matters, these details about using such a null representation and what different representations lend themselves also tends to matter. vs. gluing libraries to libraries willy-nilly. At that point this null issue is far from the main thing that comes up bc. you care about data layout enough that you have control over that representation. One example I'm running into in practice these days is--I'm using chipmunk2d game physics engine in a library. It does heap allocations, while all the component data for other stuff in my game tends go be well managed into pools that I can walk through contiguously. Even if I use a custom allocator for it, it uses pointers to refer between objects internally so I can't "move" instances of its eg. `cpBody` object around in memory. Would've been so nice to just own its data and let the library be layout-agnostic but alas. But yeah those are the data-data glues I've been interested in--libraries that kind of own representation but not location I guess. For your particular issue though, I think it really is bc. Lua is a language that out of the box doesn't tend to own representation, to the point of not eg. having its own class system etc, and it mostly shines when used in ways that play into that strength (eg. you want to wrap your own object ontology for ppl to script). The best libraries for Lua have tended to the invent their own representation and expect you to care about and own the mappings between libraries. esp. for JSON, the impedance mismatch with Lua tables puts it in this weird uncanny valley. Tbh my fav method of using JSON is to not have an in memory document format at all and just treat it as reader / writer objects directly into domain data so that you don't keep paying this intermediatw representation conversion cost. eg. https://github.com/beached/daw_json_link https://github.com/beached/daw_json_link is interesting here In my own game stuff I just have game components accept reader/writer objects to read from / write to and each component tends to have domain logic about what it means to be missing something, what some defaults are, etc.