Page 1 of 2

Lua or something else?

Posted: Wed Feb 24, 2021 2:34 pm
by dpacbach
Question for devs: if you could redo Factorio from scratch today, would you choose Lua as the scripting/modding language or some other language? Which language then and why?

Re: Lua or something else?

Posted: Thu Mar 04, 2021 3:29 am
by jamiechi1
I would prefer something else. I prefer C++ over anything else. But Lua is popular in many games and it looks like it is here to stay.

I saw on the web an article by a programmer who after many years of developing Lua, eventually came to the conclusion that C++ or another strongly typed language is much better.

Lua is a loosely typed language, which means one variable could be anything and only the developer (or programmer) usually knows what that is. With C++, every variable is explicitly typed and the compiler can check for errors in coding much easier.

One good reason for switching to the Unreal platform. At least for 3d games anyway. For this game Lua has done pretty well. Unity is nice. I think they are using C# now which is an improvement over LUA.

Re: Lua or something else?

Posted: Thu Mar 04, 2021 2:00 pm
by dpacbach
I prefer C++ over anything else
Understand that I'm talking about the modding language here. Factorio is already written in C++ as the main language. What I'm asking is, if the developers could do Factorio over again (still using C++ as the main language) what modding language would they choose?

Note that C++ not only cannot be interpreted, it must be compiled to native binary in order to be run. That means that C++ is not feasible as a modding language because then people would have to compile their mods N times for each operating system/CPU in order to distribute them. Or they could ask users to compile them, which I think is also unrealistic.

Re: Lua or something else?

Posted: Thu Mar 04, 2021 2:08 pm
by bormand
dpacbach wrote:
Thu Mar 04, 2021 2:00 pm
compile their mods N times for each operating system/CPU in order to distribute them
It's (somewhat) possible. Compile them into LLVM IR and transform that IR to native code on the user machine.

But C++ is very hard to learn. And sandboxing of native code is much harder than sandboxing of Lua scripts.

--- edit ---

Python has some problems with sandboxing... JS or .NET should be fine, but, AFAIK, they are harder to integrate than Lua.

Re: Lua or something else?

Posted: Thu Mar 04, 2021 2:40 pm
by ptx0
dpacbach wrote:
Thu Mar 04, 2021 2:00 pm
it must be compiled to native binary in order to be run. That means that C++ is not feasible as a modding language because then people would have to compile their mods N times for each operating system/CPU in order to distribute them. Or they could ask users to compile them, which I think is also unrealistic.
please just stop spreading myths around if you don't understand the problem.

do you think Factorio itself is written in Lua?

it's written in C++ and the compiler and libraries it links to are responsible for ensuring compatibility with the OS and CPUs. somehow it's not a problem that Factorio binary is compiled and passed around to many different types of systems!

did you ever see.... ANY other game that supports mods? Barotrauma's complete source code is available to modders so they can build them in C#.

Satisfactory is based on Unreal Engine 4 and some more complicated mods are compiled in C++ against the current version of UE in use by CSS.

Linux distributions support precompiled binaries, or, allow user to compile it. Windows binaries are pretty solid by now.

The problem is if Wube's binary interface (ABI) changes drastically then all mods must be recompiled. but this is how it works with Lua already! the mods must be upgraded to handle API changes.

I see no major difference other than that Lua is a pile of crap that performs like garbage and has idiosyncrasies like no "continue" statement to skip the rest of a loop; you must use 'goto'. if you want a negative comparator it's not !=, it's ~=..

i hate lua. i would prefer Rust or C++.

Re: Lua or something else?

Posted: Thu Mar 04, 2021 3:02 pm
by bormand
ptx0 wrote:
Thu Mar 04, 2021 2:40 pm
i hate lua. i would prefer Rust or C++.
Yeah... But Lua allows to write mods even if you *barely* know programming. How many people here can use C++ or Rust? How many people want to deal with obscure errors that don't fit into 20 screens or fight the borrow checker?

Honestly, C++ has way more idiosyncrasies than almost any other language. And its standard library is still a pile of crap.

And what about sandboxing? I know that most people don't care about it, but I hate native mods, especially closed source ones.

Re: Lua or something else?

Posted: Thu Mar 04, 2021 3:05 pm
by dpacbach
The LLVM IR approach sounds like it could work, if it is feasible to ship Factorio with the necessary LLVM libraries to do the IR translation (I assume it would be).

Barring that, I don't think that it is practically feasible to ask the average modder to compiler their C++ code for all the different architectures to deploy it, even if the Factorio modding API/ABI never changed. The only way I could see that working for the casual modder is if Factorio provided some kind of build server that would allow modders to upload their code to do the cross platform compilation automatically and then deploy it. But this point might be moot if the LLVM IR approach could work.

But my original question is aimed at the devs: if you could redo Factorio from scratch, what modding language would you choose?

Re: Lua or something else?

Posted: Thu Mar 04, 2021 3:56 pm
by ptx0
bormand wrote:
Thu Mar 04, 2021 3:02 pm
ptx0 wrote:
Thu Mar 04, 2021 2:40 pm
i hate lua. i would prefer Rust or C++.
Yeah... But Lua allows to write mods even if you *barely* know programming. How many people here can use C++ or Rust?
[...]
And what about sandboxing? I know that most people don't care about it, but I hate native mods, especially closed source ones.
you can do that with C++ as well. honestly, someone you don't know not knowing something isn't a reason not to include it.

closed source mods is a Wube problem - they need to enforce a licensing model in that case. it's linking to their binaries, after all.

Re: Lua or something else?

Posted: Thu Mar 04, 2021 5:11 pm
by jodokus31
related:
viewtopic.php?f=5&t=61794

but same OP

Re: Lua or something else?

Posted: Thu Mar 04, 2021 6:38 pm
by ickputzdirwech
bormand wrote:
Thu Mar 04, 2021 3:02 pm
Yeah... But Lua allows to write mods even if you *barely* know programming. How many people here can use C++ or Rust?
May I correct you: Lua allows to write mods even if you don’t know anything about programming. :D I am speaking from my own experience. All I know about programming/scripting I learned from looking at Factorio mods and messing with my own mods. All very simple stuff and I still often spent hours debugging. But it’s always a fun challenge. I didn’t even know how to open (let alone use) the windows command line. Now I wrote my own batch file to help me test my mods and had some fun writing a language package for atom for the Factorio cfg files.

Re: Lua or something else?

Posted: Thu Mar 04, 2021 7:46 pm
by Impatient
I think I remember that Rseding was very critical towards LUA in an Q&A a few years back. I tried to find that interview again but failed. No, I found it ( https://www.reddit.com/r/factorio/comme ... a/dm5fzu8/ ).


Excerpt that answers your question back then

Re: Lua or something else?

Posted: Thu Mar 04, 2021 7:53 pm
by dpacbach
think I remember that Rseding was very critical towards LUA in an Q&A a few years back.
Yes I saw that a while back as well. I was hoping to get an updated account from the devs though now that the game is finished and released, maybe their views have evolved and/or their reasons for liking/disliking Lua have changed.

Re: Lua or something else?

Posted: Fri Mar 05, 2021 12:49 pm
by Trific
Whatever language it is, it's got to hide pointers and memory management from the modder. I've interviewed CSE graduates who couldn't deal with that stuff, I wouldn't try to make Joe Random try to do it.

Re: Lua or something else?

Posted: Fri Mar 05, 2021 2:28 pm
by ptx0
Trific wrote:
Fri Mar 05, 2021 12:49 pm
Whatever language it is, it's got to hide pointers and memory management from the modder. I've interviewed CSE graduates who couldn't deal with that stuff, I wouldn't try to make Joe Random try to do it.
no way. garbage collection is one of the worst parts about Lua, and it's incredibly inefficient to mark pages for cleanup.

Re: Lua or something else?

Posted: Fri Mar 05, 2021 4:59 pm
by DaleStan
It may be inefficient to mark pages for cleanup, but I am most certainly not offering to debug memory leaks or double-free errors caused by poorly-written mods.

Re: Lua or something else?

Posted: Fri Mar 05, 2021 5:39 pm
by bormand
DaleStan wrote:
Fri Mar 05, 2021 4:59 pm
debug memory leaks or double-free errors caused by poorly-written mods
Well, poorly-written mods manage to corrupt game state or leak memory even in a safe language...

Re: Lua or something else?

Posted: Fri Mar 05, 2021 6:02 pm
by DaleStan
But it's a whole lot less common than it would be if the mods were written in C.

Re: Lua or something else?

Posted: Fri Mar 05, 2021 9:50 pm
by jamiechi1
I didn't realize c++ was a difficult language. I thought is was easy! Of course I have been programming since before personal computers existed.
Yes, an interpreter that is more like c++ can be written in c++. Lua is written in C++ I believe.

My point, is that when using a language with loosely typed variables, like LUA, it is very easy to make mistakes in the code that the interpreter or compiler can't catch.

As for anyone learning c++? If you can learn LUA, than you can learn C++. A lot of people with no programming experience are programming in c++ and don't realize it. When they play with their Arduinos.

I do agree that the various libraries for C++ are a bit difficult. I still prefer writing code before the 'managed' stuff started coming out. I like an occasional goto and sometimes I miss malloc and free. :twisted:

Re: Lua or something else?

Posted: Fri Mar 05, 2021 11:26 pm
by bormand
jamiechi1 wrote:
Fri Mar 05, 2021 9:50 pm
A lot of people with no programming experience are programming in c++ and don't realize it.
Yeah... It's quite easy to learn a comfortable *subset* of C++ and use it for your own project. It's not that easy to read the code of other people who use different subset, especially when they like templates or low-level stuff. And it's certainly not that easy to write a code that would reliably work across different compilers, CPUs and OSes. Heck, I use C++ for 15+ years and still find some obscure nuances that I don't know yet.

If C++ is easy language, then most other languages are... trivial?
jamiechi1 wrote:
Thu Mar 04, 2021 3:29 am
Lua is a loosely typed language, which means one variable could be anything
Yeah, I feel a bit uncomfortable without static types too. Especially when dealing with unfamiliar code.

Re: Lua or something else?

Posted: Sat Mar 06, 2021 5:59 am
by Trific
ptx0 wrote:
Fri Mar 05, 2021 2:28 pm
Trific wrote:
Fri Mar 05, 2021 12:49 pm
Whatever language it is, it's got to hide pointers and memory management from the modder. I've interviewed CSE graduates who couldn't deal with that stuff, I wouldn't try to make Joe Random try to do it.
no way. garbage collection is one of the worst parts about Lua, and it's incredibly inefficient to mark pages for cleanup.
I don't give a damn about whether they use Lua or not, but if you make non-programmers have to deal with pointers and memory management, you're setting them up to fail. If you can fish out a subset of C++ that avoids that, it can work, but the minute you step into "I think that's an array of pointers to.... or wait, is that a pointer to an array of..." you have loaded the gun and the inevitable is going to happen.