Lua or something else?

Post all other topics which do not belong to any other category.
dpacbach
Inserter
Inserter
Posts: 40
Joined: Sun Apr 22, 2018 1:09 am
Contact:

Lua or something else?

Post 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?
User avatar
jamiechi1
Filter Inserter
Filter Inserter
Posts: 273
Joined: Wed Jan 03, 2018 10:12 pm

Re: Lua or something else?

Post 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.
dpacbach
Inserter
Inserter
Posts: 40
Joined: Sun Apr 22, 2018 1:09 am
Contact:

Re: Lua or something else?

Post 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.
User avatar
bormand
Fast Inserter
Fast Inserter
Posts: 201
Joined: Fri Jun 05, 2020 9:59 am
Contact:

Re: Lua or something else?

Post 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.
User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: Lua or something else?

Post 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++.
User avatar
bormand
Fast Inserter
Fast Inserter
Posts: 201
Joined: Fri Jun 05, 2020 9:59 am
Contact:

Re: Lua or something else?

Post 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.
dpacbach
Inserter
Inserter
Posts: 40
Joined: Sun Apr 22, 2018 1:09 am
Contact:

Re: Lua or something else?

Post 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?
User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: Lua or something else?

Post 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.
User avatar
jodokus31
Smart Inserter
Smart Inserter
Posts: 1623
Joined: Sun Feb 26, 2017 4:13 pm
Contact:

Re: Lua or something else?

Post by jodokus31 »

related:
viewtopic.php?f=5&t=61794

but same OP
User avatar
ickputzdirwech
Filter Inserter
Filter Inserter
Posts: 794
Joined: Sun May 07, 2017 10:16 am
Contact:

Re: Lua or something else?

Post 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.
Mods: Shortcuts for 1.1, ick's Sea Block, ick's vanilla tweaks
Tools: Atom language pack
Text quickly seems cold and unfriendly. Be careful how you write and interpret what others have written.
- A reminder for me and all who read what I write
User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Re: Lua or something else?

Post 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
dpacbach
Inserter
Inserter
Posts: 40
Joined: Sun Apr 22, 2018 1:09 am
Contact:

Re: Lua or something else?

Post 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.
Trific
Fast Inserter
Fast Inserter
Posts: 155
Joined: Thu Dec 31, 2020 7:57 pm
Contact:

Re: Lua or something else?

Post 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.
User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: Lua or something else?

Post 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.
DaleStan
Filter Inserter
Filter Inserter
Posts: 374
Joined: Mon Jul 09, 2018 2:40 am
Contact:

Re: Lua or something else?

Post 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.
User avatar
bormand
Fast Inserter
Fast Inserter
Posts: 201
Joined: Fri Jun 05, 2020 9:59 am
Contact:

Re: Lua or something else?

Post 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...
DaleStan
Filter Inserter
Filter Inserter
Posts: 374
Joined: Mon Jul 09, 2018 2:40 am
Contact:

Re: Lua or something else?

Post by DaleStan »

But it's a whole lot less common than it would be if the mods were written in C.
User avatar
jamiechi1
Filter Inserter
Filter Inserter
Posts: 273
Joined: Wed Jan 03, 2018 10:12 pm

Re: Lua or something else?

Post 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:
User avatar
bormand
Fast Inserter
Fast Inserter
Posts: 201
Joined: Fri Jun 05, 2020 9:59 am
Contact:

Re: Lua or something else?

Post 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.
Trific
Fast Inserter
Fast Inserter
Posts: 155
Joined: Thu Dec 31, 2020 7:57 pm
Contact:

Re: Lua or something else?

Post 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.
Post Reply

Return to “General discussion”