Mike McGonagle wrote:
Wow Claude, last night I rewrote several of my old externals that were originally in C, in Lua last night... And they required about 1/4 of the code that C requires. I am pretty much sold on using Lua now...
Cool :-)
I guess one of the things that seemed to scream out at me was "How would Lua and PD work together"? While I know this is a pretty broad and general question, I was wondering, with you as the developer of the Lua stuff, just how do you see Lua fitting in with PD? What sorts of things would be best done in each language?
I use C for things requiring lots of numerical computations.
I use Lua for things requiring a more dynamic language, for example handling multi-modal keyboard input. Also for processing small arrays in ways that would be awkward with Pd-implemented loops.
I use Lua for string processing in general, as C is horrid for that.
One of the things that I like (if I understand this correctly) about using Lua, as that everything is now accessible programmatically.
I think you mean that you can change things within Lua at runtime more readily than in C? This is true, it's also true that dynamic typing can lead to more subtle bugs than C's static typing.
I do have a couple of questions...
- Is it possible to access from Lua, the elements of a table object
that is defined in PD?
Not yet, but it's pretty high on the TODO list (at least the one in my head).
- Can data struct's be accessed from Lua?
Not yet, and I'm not sure if that will ever be safe, even if it is possible. There was a prominent warning in an earlier version of pdlua that stated "pointer atoms are untested/unsafe", but I removed it by request, as other externals are in the same category but don't warn the user.
- Is it possible to load Lua objects using a path? (ie
[my-lua-directory/my-lua-external.lua]) If something written in Lua is supposed to look like other PD externals, then I would think this would work with Lua externals as well.
Have you tried it? I have a hunch that it might Just Work (TM), if not then let me know and I'll investigate.
- Are there things that you wouldn't do in Lua? For performance
reasons? Other reasons?
Vast amounts of number crunching, for performance reasons. This includes DSP at the moment, although hopefully Frank's port of Lua~/Vessel~ is a viable alternative (not sure what the current status of that is).
System calls, for "Lua doesn't have C structs" reasons - you'd have to write C code for them to call them from Lua anyway, so not much point.
I guess I am asking these things because I could see it possible that I could rewrite almost everything in Lua, and then passing on the control data to the PD objects to generate the sound. One of the "line of division" that I was thinking about for my own stuff would be to write all the control stuff in Lua, and then feed that data to PD for the audio generation.
Yes, that seems a sensible approach. Just in case, note that it's no sin to split the Lua code into multiple classes and connect them together as separate objects inside a Pd patch - modularity is a good thing.
Thanks for this work you have done (and to others, as well).
Thanks for the feedback,