Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: it's scripts all the way down!

by perlfan (Curate)
on Mar 15, 2016 at 14:40 UTC ( #1157807=note: print w/replies, xml ) Need Help??


in reply to it's scripts all the way down!

What is to be gained from embedding lua inside a perl script?

You can offer the users of your program a domain specific language (DSL); Lua is best know to provide support for this in particular. You mention Nmap and Snort, but mysqlproxy also uses it. It's used extensively to extend complex programs written in complex languages, e.g. C++ (WoW?). Redis is getting increasing support for Lua.

Do lua coroutines provide anything useful when used in a dominantly Perl context? (Useful could be something to gain in maintainability, performance, scalability...)

Sure, it can provide you with a way to manage many contexts by which you are doing work. Don't confuse this with multi-threading, but it can provide you with a cheap mechanism (i.e., context switching) to manage lots of unrelated blocks of work in the same execution thread. From what I've seen, I don't think Lua supports actual threads. http://www.qore.org is embeddable and supports threading, but I don't think it's as nice as Lua for this purpose.

Why isn't perl embedded in applications as often as lua is (especially since TinyPerl is the same size)?

Lua evolved to fit this explicit purpose. Perl is too heavy and doesn't provide the clean ways of binding a host program to the underlying Lua interpreter that make it a nice choice for building a DSL into your program.

Update - you mention FFI::Platypus, but that's primarily for creating wrappers around shared libraries. It might help you avoid writing an XS module directly, but it's not going give you the solid platform for a DSL like Lua.

PS: good reading on the history of Lua - http://www.lua.org/history.html

Replies are listed 'Best First'.
Re^2: it's scripts all the way down!
by QuillMeantTen (Friar) on Mar 16, 2016 at 08:11 UTC

    Thank you for your reply,
    I found it to be most enlightening and took the time to read through your links and on DSLs.
    As I studied language theory and had to come up with a toy one I kinda related to different posts I found online warning people against DSLs.
    I have three follow up questions on that topic.

    • Beside the easily found example that I felt only scratched the surface, how spread is the use of DSLs?
    • Furthermore, when taking into account the difficulty of designing and maintaining a language (I found grammar and syntax to be complicated to do well, but it might just be me) why not use pure lua to script your application?
    • What are some good ressources on the most maintainable design patterns used when you need to come up with an architecture for supporting user written addons? (I read Module::Pluggable documentation's but I could not think of a way to make it able to directly use lua scripts without having to wrap each of them in a perl module

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1157807]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2018-09-21 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (186 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!