lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Wed, May 30, 2018 at 10:06 AM, Kevin Wang <> wrote:
Hi everyone,

I am just getting into Lua to research it as a possible language for a grant we are working on, and was wondering if anyone could answer some questions for a beginner :)

We write software and hardware for neuroscience experiments, and are developing a new tool. Our ultimate goal in a nutshell is to have users be able to write and run scripts on their computers, but only as simulation and without low latency. The idea is that once they are satisfied with fine tuning their control script and parameters, they can then "upload" it to our device (a soft-core processor on an FPGA), in which case our backend can execute their control script with direct access to the data (going through the FPGA) for extremely low latency.

So my questions are:

1. Is Lua syntax easy to learn, especially for users that primarily code analysis scripts in Matlab or Python? (Even if it is not, if Lua turns out to meet our tech requirements, they'll just have to learn Lua anyways. Just a good thing for me to keep in mind)
IHMO Lua is very easy to learn because the language is so small. That said, there are things about Lua that are not friendly to non-technical people (meta-tables, functional programming, upvalues) but very powerful for intermediate to advanced users. It also has some quirks, but overall is a very simple language. One thing to note is that Lua string manipulation and pattern matching  is *very* different than what most people expect. Once a person is familiarized with the Lua string patterns, it's hard to go back to indexes and regex. However, string manipulation was a hefty speed bump for me and it could be a considerable learning curve for some.

In terms of learnability and performance: Lua is used extensively in games for user extensions. As an example, Roblox games are written entirely in Lua by the Roblox users.  I'm not sure if they are using Lua "Proper" or LuaJIT though (the language was forked some years back).

Where things tend to get difficult in Lua is the lack of a standard library. That's a good thing in some senses (no bloat), but it means you're going to need to provide an API for your users by importing or writing Lua Modules. You might be able to get away with just importing something like Penlight, (Moses would be good if you're making calculations), but Lua the language gives you very little for free (compared to say Python on Java). 

Another thing will be squashing down the Lua scripts and getting them onto the embedded system and loading them. The tool called squish seems to be a good one, though I had no success with it in my 5 minute attempts on Windows. 

2. Is this a fair use case for Lua? I know that Lua is small enough to use on embedded devices, what about an FPGA?
- eLua is designed for microcontrollers and what-have you. I haven't used eLua but have a lot of interest in it: 
- I've been coming up to speed on RTEMS and recently got a hello world working with that. RTEMS can be run on an FPGA configured as a LEON2 processor - but I don't have an FPGA. I'm using the ERC32 simulator in a FreeBSD VM.

3. Does anyone here have a similar use case that I could talk to, or see any similar examples for?
Your use case is what I am *trying* to do: Allow people to write scripts on Windows or Linux and then run it on something embedded.  On the user scripting side, I have a WinLua project that is supposed to help people start programming in Lua on Windows. ZeroBrane Studio IDE would also be a good platform for your "user scripting interface". 


4. If not Lua, any other recommendations?

I personally found/find the Lua C API difficult so I've started including a header only C++ wrapper called Sol2 in my WinLua project. If you support C++ 17 it might be worth looking at. 

The term you are looking for is "Glue Language". TCL is an example, but good luck on the syntax. A person named Peter MacDonald (created the first Linux Distro) as created an embeddable _javascript_ interpreter called jsish (_javascript_ Interpreter Shell). He has taken a different approach and included everything he thinks you'll need as an embedded developer. Jsi comes with a socket library, websockets, sqlite integration and a built in debugger (command line or web interface). Those tools will cost you in terms of size though.

Are you looking for Machine learning? Check out (though I think it's broken right now).

Many many thanks,
Good Luck, please keep us informed of you're progress, I'd love to hear more!