Sam Trenholme's webpage
Support this website or listen to my music

The one true language

 

April 1 2021

Lunacy is the one true programming language. April fools!

==Lunacy==

April fools, because the idea of the one true programming language is a foolish idea. The best programming language to use is the one your peers are using, or the one the project has already been written in. The best tool for the job.

That said, I have finally found a programming language which nicely fills the gap between Sed/AWK and the “big” languages like Python/Perl/PHP/Java: Lunacy, which is my personal “Lua with batteries” language. This is a fork of Lua 5.1 (to save some size) with a number of useful third party libraries built in to the code.

== Lua: No batteries ==

Lua’s main issue is that it is a bare-bones language optimized to be as small as possible.

That in mind, things like dictionary sorting, copy.deepcopy, and even regular expression splitting take up more code. Let’s look at what an AWK-like script looks like in Lua:

-- Code is public domain
function pStrSplit(s, splitOn)
  if not splitOn then splitOn = "," end
  local place = true
  local out = {}
  local mark
  local last = 1
  while place do
    place, mark = string.find(s, splitOn, last, false)
    if place then
      table.insert(out,string.sub(s, last, place - 1))
      last = mark + 1
    end
  end
  table.insert(out,string.sub(s, last, -1))
  return out
end

l = io.read()
while l do
  f = pStrSplit(l,"%s+") -- AWK-style split: f[1] is $1, etc.
  -- process as needed
  print(l)
  l = io.read()
end
-- END public domain code

Here, we needed to add a Lua function which does regular expression string splitting, since while Lua has some regular expression support, it doesn’t have a split() operation.

== Lunacy: Lua with batteries ==

Lunacy, my personal fork of Lua 5.1, does include a number of batteries:

  • Secure hash compression
  • Strong random number generation
  • A subset of Luafilesystem
  • Most of bit32 for bitwise operations
  • Desktop calculator support
  • Better sub-process support (two-way pipes)
  • LUAstuff folder with other batteries implemented in Lua: Sorted table iterators, regular expression splitting, copying files, etc.

Lunacy is available for download at GitHub and Sourcehut. It’s also possible to download the source code and Windows binary locally. Note that 7-zip is needed to unpack the Windows binary.

Comments for blog entries can be seen in the forum.

Previous entry - Next entry - Blog index