Thread for basic help understanding the lua documentation or lectures etc

I hope that this thread is suitable and helpful and not a waste of forum space. I’ve started the lua lectures, and have a few stumbling blocks in understanding them, due to my complete lack of familiarity with computer science and programming… so, if I may start out? And please advise where I might ask, if not here!

Here’s some questions having read the first set of lecture notes on lua (I did not understand the slide on simplicity at all but will leave that for now). Forgive me if I seem super foolish.

I found the wikipedia articles often used examples of e.g. ‘execution model’ rather than a complete defitnion. So, from the 1st lecture:

  1. scripts are "programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator."
    But what is a runtime environment? “Runtime system behavior is, arguably, defined as any behavior not directly attributable to the program itself” so does that simply mean that lua, being a scripting language, is written for something (what?) that is not controlled by lua?

  2. I understand that an API is like a GUI for programmers. So it’s an interface, for use by the programmer, right? What does this mean, can I e.g. have a screengrab of what it can look like?

Questions about the meaning of some specific statements in the slides:

  1. “The Lua interpreter is a library for C programs” does this mean that lua is interpreted, the code executed without being compiled first, by a library that is part of C?

  2. “Programs in other languages can easily consume the API” does this mean that other languages (C#, perl) can be used by the programmer as she her interfaces with the API?

From the 2nd lecture:

  1. I am using eclipse, and trying to create a file defs.lua for use with the REPL for a project “Starting out”. But after starting that project and entering in main the code
    local function main()
    end
    main()
    dofile(“defs.lua”)
    print(fact(5))
    and creating a new file defs.lua (apparently saved as “Starting out/src/defs.lua”) with the code
    function fact(n)
    if n < 2 then
    return 1
    else
    return n * fact(n-1)
    end
    end
    I get an error message when I run main.lua, saying that no such file as defs.lua. How am I using eclipse wrong?

  2. And what is the word for the variable between brackets, is it an “argument” for the function?

2 Likes

Hey @vqlk. First off, let me be clear that you don’t need to learn Lua to make your ER-301 do all sorts of fun, interesting, and useful things. To my knowledge there are very few users creating ER-301 units with Lua at this point.

I’d say it’s more important to learn the signal flow and the concepts in the ER-301 by using the visual patching language before you think about trying to do something in the middle (Lua) layer.

It’s great that you’re interested in learning it though.

With respect to the ER-301 your run time environment will be the ER-301 itself. Your Lua code is interpreted by the ER-301 and used to create DSP objects, patch them together, and create the user interface.

In the case of the ER-301, Lua can be used to create a Unit. The ER-301 is controlled by its custom operating system. If you load a user-written Lua unit (we call those bespoke units here), then the Lua code for that unit is executed, which constructs all of its DSP building blocks, connects them together, and creates the user interface (controls, menus, etc.).

An API isn’t really a GUI in this case. It’s a set of routines/functions that Brian has created that can call underlying operating system code. An example might look like this:

self:createObject("Multiply","multiply")
connect(multiply,"Out",pUnit,"Out1")

Here createObject and connect are not a built in part of the Lua language. They are part of the API that Brian created. They construct a DSP object within the ER-301 and patch it to some other DSP object, respectively. The API has not been documented officially at this point - only through code examples and Q&A.

Correct, it’s not compiled. It is interpreted by a Lua interpreter running on the ER-301. The ER-301 does do some checking of your code, to make sure it is valid.

I don’t think that’s applicable here - my understanding is that the lower level code in the ER-301 is a c/c++. Though it might be applicable more broadly when talking about Lua.

4 Likes

Amazing thanks, great answers! I’m going to have to spend a while working out why I can’t use eclipse

you don’t need to learn Lua to make your ER-301 do all sorts of fun, interesting, and useful things

That’s obvious, I just want more things to do when away from the synth, not just think of patches and or chains. I’ve been through a good part of the documentation already

Questions from the 2nd lecture

  1. it seems that the defs.lua has to be placed in the parent folder for the project if dofile in main.lua is going to use it
  2. yes that bracketed texts are arguments

That is probably because Eclipse is executing the Lua interpreter in your project folder so that the project folder becomes the current directory from the point of view of the Lua interpreter. Then when you call dofile("defs.lua") without any path information it just looks in the current directory for this file.

Which makes me wonder if Eclipse is just getting in the way of you learning the Lua standard environment? Eclipse is a huge program with lots of features. It adds a lot of stuff (useful stuff if you are already in the know) that could confuse. Personally, I would just start with the command line and a syntax-aware text editor (like Atom or Visual Code). Create Lua scripts in the text editor and then manually run the Lua interpreter on the scripts yourself at the command-line. This is exactly what Eclipse is doing under the hood. Once there are no more mysteries on the Lua side then you can move to Eclipse for convenience.

That being said. When it comes to learning a programming language as a non-coder, you probably should not be getting advice from me. I’m pretty out of touch. :blush:

By the way, these are brackets [ ], these are parentheses ( ), and these are curly braces { }. They are all used for different things in Lua.

3 Likes

Yes, in Lua these are called arguments.

function fact(n)

fact is a function that accepts an argument n.

I might also call n a parameter, which would be semantically incorrect for Lua. But people who code in a variety of languages might use those terms interchangeably.

Also if you have not found this thread yet, I made a video a while back about developing in the middle layer. I’ve learned a lot since then - it was very early on in my experience. But it might give you a little context around Lua and the ER-301.

I’ll go thru the lecture slides 1st. A few hiccups in understanding the lectures’ basic examples so far, but I’m hoping that the further I get into this the less background knowledge I’ll need. At least

1 Like

Am I right that the “value” of the “argument” is a “parameter”. Or perhaps vice versa

I’m confused by return statement. I can guess what it does but am unsure exactly, because I haven’t read a description of what it does

If you load a user-written Lua unit (we call those bespoke units here), then the Lua code for that unit is executed, which constructs all of its DSP building blocks, connects them together, and creates the user interface (controls, menus, etc.).

While I am enjoying the process, I’m unsure, reading back thru the thread, what result will be. If dsp blocks are built with C then can you do anything with lua that you can’t with the er-301 out the box besides changing the user interface for them

I think they’re still called arguments. They are just called different things in different languages. E.g. in javascript they are called parameters. I’m not 100% sure though - frankly I don’t get too hung up on this kind of thing.

If you had

x = 0
x = foo(x)
function foo(num)
 return num + 1
end function

then x would come out equal to 1.

I think the 0.4 firmware as of right now does a lot to close the gap between what you can do in the UI vs the Middle Layer. But still, there are advantages. There are objects available in the Middle Layer that aren’t directly available in the UI. The routing can still be a bit more flexible. You can build something a bit more CPU friendly in the Middle Layer because you’re only grabbing the objects that you need vs. you might not need all the things that come along with a particular Unit in your Middle Layer patch.

Also, the DSP SDK (c++ layer) will come out at some point, and if you create any custom DSP, you’ll need to know the Middle Layer to be able to use it in a Unit.

Thanks, that was helpful

I don’t get too hung up on this kind of thing

ha yeah, definitions… just afraid of getting somewhere and finding out that I’ve misunderstood everything I’ve learnt! Like quantum mechanics maybe :grinning:

.

Don’t worry about replying; but I wondered what “in” means. e.g.

ipairs (t)

Returns three values (an iterator function, the table t, and 0) so that the construction

 for i,v in ipairs(t) do body end

will iterate over the key–value pairs (1,t[1]), (2,t[2]), …, up to the first nil value.

All I’ve worked out, via trial and error, is that you can delete “i” or “v” from the statement and the for loop still works, and then the remaining variable (i or v) will run through the sequence of integer keys and not their values

So far more than a third of the way thru :grin: