In which language you want to write mods?

Post Reply
TillCoyote
Member
Posts: 30
Joined: Sat Jan 26, 2019 08:05
Location: Kasachische Republik

In which language you want to write mods?

by TillCoyote » Post

Not everybody likes Lua, that's used in Minetest, some enthusiasts try to make support of other languages. What language would you use for Minetest mods coding?

User avatar
Linuxdirk
Member
Posts: 3217
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: In which language you want to write mods?

by Linuxdirk » Post

TillCoyote wrote:What language would you use for Minetest mods coding?
After considering all the pros and cons: Lua is absolutely fine. I just wish Minetest would use a more recent version and LuaJIT without those extreme memory usage issues.

User avatar
Festus1965
Member
Posts: 4181
Joined: Sun Jan 03, 2016 11:58
GitHub: Festus1965
In-game: Festus1965 Thomas Thailand Explorer
Location: Thailand ChiangMai
Contact:

Re: In which language you want to write mods?

by Festus1965 » Post

Code: Select all

 TillCoyote
    New member
    Posts: 5
a quit less posts for this question ... strange

but I learned C++ but no training anymore
I would like to understand Lua better - but too late I guess
Human has no future (climate change)
If urgend, you find me in Roblox (as CNXThomas)

User avatar
Pyrollo
Developer
Posts: 385
Joined: Mon Jan 08, 2018 15:14
GitHub: pyrollo
In-game: Naj
Location: Paris

Re: In which language you want to write mods?

by Pyrollo » Post

Festus1965 wrote:I would like to understand Lua better - but too late I guess
I guess you can, LUA is cleverly simple. And, I my opinion, that makes it very interesting.
TillCoyote wrote:Not everybody likes Lua, that's used in Minetest, some enthusiasts try to make support of other languages. What language would you use for Minetest mods coding?
You should have a look on forum topics about this. I guess all is said already.
[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]

TillCoyote
Member
Posts: 30
Joined: Sat Jan 26, 2019 08:05
Location: Kasachische Republik

Re: In which language you want to write mods?

by TillCoyote » Post

Festus1965 wrote:

Code: Select all

 TillCoyote
    New member
    Posts: 5
a quit less posts for this question ... strange

but I learned C++ but no training anymore
I would like to understand Lua better - but too late I guess
I firstly played in ~2013. That's not my first account.

User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: In which language you want to write mods?

by Wuzzy » Post

Minetest should stick with Lua because it's so simple and it has served us fine over the years.
Lua as a language is okay, but it has flaws. It has some design flaws, like that the default variable scope is global or it's dynamically typed or that it doesn't automatically fail on type errors. “Undeclared global” is probably the #1 bug in Lua code. But there are tools to detect some of the common bugs.
I would not want to change the language.

Switching the scripting language at this stage would be insane, plain and simple. We would basically have to throw away all mods and games. So I don't see the point in this thread. Even if we agreed that <OVERHYPED LANGUAGE XYZ> is better, we should not switch now.

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: In which language you want to write mods?

by rubenwardy » Post

Lua is well suited to game scripting, due to its simplicity. It's not well suited for large projects, which is why I always recommend to keep mods small and focused, and to use multiple mods. Lua is possibly one of the best languages out there, if you rate its design, because it is simple, well-designed, and good at what it does. There are, however, a lot of issues with the Lua ecosystem - including language fragmentation and an unmaintained LuaJIT.

There will never be another first class scripting language for Minetest like Lua. We will never have a Python API in the exact same way. Simply because so much depends on there only being one scripting environment. Now, we may add support for extensions using C ABIs, but this is likely to be limited to adding new mapgens and other such time-sensitive operations.

An alternative to adding first class language support would be to wrap a language in Lua. This either involves Lua running some form of interpreter, or Lua using sockets to communicate with another program and language. The latter is my recommended approach for adding support for Python for educational reasons. In fact, this is how it is implemented on the RPi version of Minecraft. Such an approach would define a generic protocol which would allow a number of different languages to connect and control things, such as Python or Blocky - a scratch clone
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Linuxdirk
Member
Posts: 3217
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: In which language you want to write mods?

by Linuxdirk » Post

rubenwardy wrote:Lua is well suited to game scripting, […]
And it is actually used for this by a lot of developers which makes it just the perfect choice – And the list is just a small collection of Wikipedia-relevant entries.

Skulls
Member
Posts: 108
Joined: Thu Dec 21, 2017 17:41
In-game: Skulls

Re: In which language you want to write mods?

by Skulls » Post

Lua is a pain in the rear to use for me because it lacks interfaces or user defined types / classes. This is a major hurdle when building an API or a framework because you know it is going to be issues when folks try and use your code. These constructs are helpers to keep people from shooting themselves in the foot and generally having them speeds things up. Its like C. I don't like it.

HOWEVER, it is fast. And small. And well designed for what it does. And it is a great fit for most mods, large and small. I think that if you wanted a heavier language to support a huge project you probably should plan on writing a Minetest server because then you can use all the language sugar you would like and make a super cool behemoth. But for mods Lua is a good choice. The only other one that would work really well for Minetest would be something like GDScript from the Godot project but I don't think that would be easy to port over.

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: In which language you want to write mods?

by rubenwardy » Post

Lua is designed to use the prototyping approach to
oop

Code: Select all

local Company = {}
company.Company = Company

--- Constructor
function Company:new(obj)
	obj = obj or {}
	setmetatable(obj, self)
	self.__index = self

	-- Members
	self.ceo     = nil
	self.members = {}
	return obj
end

-- Methods
function Company:get_ceo_name()
	return self.ceo
end

-- Objects
local mycompany = Company:new()
https://github.com/CapitalismGame/capit ... ompany.lua
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: In which language you want to write mods?

by sorcerykid » Post

Wuzzy wrote:Lua as a language is okay, but it has flaws. It has some design flaws, like that the default variable scope is global or it's dynamically typed or that it doesn't automatically fail on type errors. “Undeclared global” is probably the #1 bug in Lua code.
The default global scope is actually intentional and with good reason, because "without local declarations, you cannot say where the variable is local to." (source: RiciLake, Lua User's Wiki).

http://lua-users.org/lists/lua-l/2006-10/msg00063.html

In truth, Lua is a fast and easy language for rapid prototyping. I believe it's biggest flaws are 1-based arrays, lack of bitwise operators, and no support for proper modules and libraries (sorry, dofile/require doesn't cut it).
Rubenwardy wrote:Lua is designed to use the prototyping approach to oop


I find metatables to be rather non-intuitive as a means to OOP (albeit fine for operator overloading). It's unusual that members of objects have to be declared outside the scope of the constructor, that object methods have to be passed a "self" variable explicitly (and enforce that bug-ridden colon for method invocation), and that member functions and variables are never truly private.

This is why I prefer the closure approach, which overcomes these issues and is very simple to comprehend and maintain. It also happens to be similar Javascript, so transitioning between languages is effortless :)

Code: Select all

local function Company( self )
     local members = {}             -- private
     local ceo = ""                 -- private
     self.get_ceo = function ()     -- public
          return ceo
     end

     return self
end

local mycompany = Company( {} )

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: In which language you want to write mods?

by rubenwardy » Post

Lua and Javascript are both prototyping languages, so metatable classes in Lua are equivalent to prototype classes in Javascript.

Code: Select all

function Company() {
    this.members = {}
    this.ceo = ""
}

Company.prototype.get_ceo = function() {
    return self.ceo
}
Javascript has syntactic sugar (via the class keyword) to make classes nicer to write, but the internals are the same.

A closure to make data private is a common pattern in JS, due to the lack of namespacing in the browser

I'd personally argue that having cleaner code and separating the data and the prototype (ie: methods) is more important that hiding a variable, when you can mark a variable as private using __ceo, but ultimately it doesn't matter too much
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Post Reply

Who is online

Users browsing this forum: Google [Bot], Trog and 11 guests