Page 1 of 1

In which language you want to write mods?

PostPosted: Tue Feb 12, 2019 09:11
by TillCoyote
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?

Re: In which language you want to write mods?

PostPosted: Tue Feb 12, 2019 09:41
by Linuxdirk
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.

Re: In which language you want to write mods?

PostPosted: Tue Feb 12, 2019 09:44
by Festus1965
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

Re: In which language you want to write mods?

PostPosted: Tue Feb 12, 2019 09:51
by Pyrollo
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.

Re: In which language you want to write mods?

PostPosted: Tue Feb 12, 2019 16:26
by TillCoyote
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.

Re: In which language you want to write mods?

PostPosted: Tue Feb 12, 2019 16:39
by Wuzzy
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.

Re: In which language you want to write mods?

PostPosted: Tue Feb 12, 2019 16:44
by rubenwardy
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

Re: In which language you want to write mods?

PostPosted: Tue Feb 12, 2019 18:58
by Linuxdirk
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.

Re: In which language you want to write mods?

PostPosted: Wed Feb 13, 2019 04:08
by Skulls
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.

Re: In which language you want to write mods?

PostPosted: Wed Feb 13, 2019 08:38
by rubenwardy
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

Re: In which language you want to write mods?

PostPosted: Wed Feb 13, 2019 11:40
by sorcerykid
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( {} )

Re: In which language you want to write mods?

PostPosted: Wed Feb 13, 2019 11:52
by rubenwardy
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