Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lua Scripting 101: Hello World!
#1
We've had a couple of requests for a very simple introduction to Lua scripting in Mixbus.

When learning a new computer language, it is customary to start with a minimal program that prints "Hello World".

So, here it is: the tiniest possible Lua script in Mixbus!

[Image: lua-hello-world.png]

To try this out, click Window/Scripting, and copy/paste this text into the window, as shown above:

Quote:function factory () return function ()

print("Hello World!")

end end

then click the "Run" button. You should see "Hello World!" appear in the lower window.


More examples coming shortly....


-Ben
Reply
#2
jabney Wrote:So what do the two "end" "end" actually end? The two "function"s themselves? There are also three pairs of () and those must mean something.

best, john


Short Answer:

They are necessary for the function to be recognized by Mixbus's Lua interpreter, but you don't have to know why.


Long answer:

Mixbus's Lua interpreter is looking for several different things: for example there should be a header (which defines the script's name, etc), the arguments that should be requested of the user and passed into the function, and the function itself.

These little blocks (defined by function()/end or whatever) tell Mixbus's Lua interpreter what is available inside the script.

In the "Hello World" example, I've provided the bare minimum which is basically saying "Hey, Lua, here's a function for you to call. There's no header, or additional arguments, or anything else; sorry!"
Reply
#3
And the extra long story:

Mixbus "produces" a function call by calling the factory function. And later refers to the produced unique instance of function.
This allows to re-use the same script many times with different instance parameters and also makes it possible to those instances to share variables which are part of the factory (not global). That can be handy for example to have a 3-step script which cycles through actions.

All Editor Actions run in the same interpreter (in the GUI thread) and hence can also share data globally.
Reply
#4
(03-30-2017, 08:35 AM)Ben@Harrison Wrote: We've had a couple of requests for a very simple introduction to Lua scripting in Mixbus.

When learning a new computer language, it is customary to start with a minimal program that prints "Hello World".

So, here it is: the tiniest possible Lua script in Mixbus!

[Image: lua-hello-world.png]

To try this out, click Window/Scripting, and copy/paste this text into the window, as shown above:

Quote:function factory () return function ()

print("Hello World!")

end end

then click the "Run" button. You should see "Hello World!" appear in the lower window.


More examples coming shortly....


-Ben

Wow !

Great ! Although my first programming experience predates Hello world which i think was started by Brian and Dennis : The C book .
My first lines looked more like : 01001100 11001101

=-=
I am very happy about lua : and i see examples appearing , and already with uer examples.

I am afraid, that those examples will be intermingled with other issues : would it not be to have a Lua section on the forum : even with a subdivisions :
1 / scripts
which contains working scripts
2/ Q/a or so : questions and answers from/to users

This way they are easy to find, and not scaring off people : No you do not need to learn how to program to use Mixbus

regards
Frank W. Kooistra

- MMB32C 9.1, AD/DA: Motu:1248, 8A, 8D, Monitor8. X-Touch,, Mini M1 11.6.2, venture 13.3 plugins melda fabfilter harrison No Harrison CP-1 
Reply
#5
(03-31-2017, 01:09 AM)Frank Wrote: [
I am afraid, that those examples will be intermingled with other issues : would it not be to have a Lua section on the forum : even with a subdivisions :
1 / scripts
which contains working scripts
2/ Q/a or so : questions and answers from/to users

This way they are easy to find, and not scaring off people : No you do not need to learn how to program to use Mixbus

regards

This
Windows 7 x64 SP1
Mixbus 32C 7.1.92
Reply
#6
I am working with individual words, individual spaces e.g. [mark spc], and marks e.g. [mark ! ]. Here is what I want to see on the far left of my own Mixbus under "Strips" - Mixer View:
. Full Sentence - Hello World!
. Hello
. [mark = spc ]
. World
. [mark = ! ]
. [mark = spc1]
Currently, the text under "Strips" is renamed from Audio 1 to Audio 6 (for this case). Not sure if there is a better way at the moment. Eventually, an Artificial Intelligence engine will be built to handle that task.

What would be very useful to me is to have Zooms to 5 second and 2.5 second as options. Sometimes a 10 second window leaves too much empty space, while sometimes a 1 second .wav is too short.

(This is for a free app that started out for people that need help in speaking or hearing individual words, i.e. 'Word Deafness' - or both. The scope has broadened, though. Now I hope to utilize Mixbus and/or Audacity, so that people at every income level can feel welcome.)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)