:: Re: [DNG] Lua
Inizio della pagina
Delete this message
Reply to this message
Autore: onefang
Data:  
To: dng
Oggetto: Re: [DNG] Lua
On 2024-10-18 08:24:13, onefang wrote:
> On 2024-10-17 09:59:49, Hendrik Boom wrote:
> > On Thu, Oct 17, 2024 at 12:30:49PM +0200, Didier Kryn wrote:
> >
> > > I remember Lua as a pretty decent high level language
> >
> > a bit like a Lisp with syntax and fewer parentheses.xc
> >
> > My daughter uses Lua preferentially. I find her code hard to read.
>
> Peeps can right ungoodly in any language. They even have competitions.


Recently I have been writing my ALSA / JACK connect everything script
that I call aataaj, pronounced "attach".

In Lua.

My initial idea was to connect all things to JACK, so that you could
start with a fully populated patchbay, then work from there. Fsmithred
though it would be good to also work at a lower level, at an earlier
time. Have the part that finds all the audio devices find something
suitable for espeak to start speaking the boot output, and everything
else on screen. From as early in the boot sequence as possible. Got it
working in SysV init's run level S, which runs before run level 2.

This involved a few rabbit hole dives.

The wrapper around the various shell commands I run is from
apt-panopticon, where mostly it wraps curl. One rabbit hole was to break
that out properly, turning it into something a bit more generic. Then I
got carried away. lol

So now I have ended up with an experiment I want to call PolygLua.
Gluing things onto Lua, making it a polyglot language. The basic idea
being the same as that old joke "I can write FORTRAN in any language.",
in this case you can include any scripting language in your Lua script.
Could be possible to get it to deal with compiled languages as well, but
think I'll dodge that rabbit hole for now.

Sooo, I can write Lua in any language. B-)

So an example Lua script -

---------------------------------------------------------

local _ = require '_'

__[[#!/bin/bash
    echo "Hello world from bash."
]]:log():show():Do()


__[[#!/usr/bin/env luajit
    print('Hello ' .. "world " .. [=[from]=] .. " Lua.")
]]:log():show():Do()


__[[#!/usr/bin/perl
    print "Hello world from perl.\n";
]]:log():show():Do()


 -- No idea why this isn't working.
__[[#!/usr/bin/php
<?php
    print("Hello world from PHP.");
?>
]]:log():show():Do()


-- Note no indent for Python, coz whitespace is significant.
__[[#!/usr/bin/env python3
print("Hello world from python.")
]]:log():show():Do()

__[[#!/usr/bin/ruby
    puts "Hello world from ruby."
]]:log():show():Do()


---------------------------------------------------------

In Lua you have several types of string, which the Luajit example
demonstrates. A multiline string is anything between [[ and ]]. You can
turn that into a multiline comment by putting the usual Lua comment
starter at the beginning. So that's "--[[ blah blah blah ]]".

In the above code I have defined a function called __ that is in the
library caled _. You can pass a string to a function by just including
the string after the function. So in this case I pass strings to __ like
this "__[[this can be a multiline string]].

Just like shell script files, that multiline string can begin with a #!
line that tells it what language interpreter to use. In the above code I
do "Hello world" in six different languages. As far as the interpreter
for any language is concerned, it's just passed a temporary file it tries
to interpret, the file contains the contents of the string you passed to __.

Then you can do various things with it, and eventually Do() which runs it.

Not sure what's up with the PHP example.

--
A big old stinking pile of genius that no one wants
coz there are too many silver coated monkeys in the world.