Lua Is Embedded

I’ve been writing some Lua while hacking away on the micro text editor.

The language feels like it is missing a lot of basic functionality.

For example: trimming a string, which should be easy, requires copying/pasting some code:

-- http://lua-users.org/wiki/StringTrim
function trim(s)
    return s:gsub("^%s*(.-)%s*$", "%1")
end

Lua is being embedded into the editor through Go. So the missing functionality isn’t an issue because most of the Go standard library is also added to the environment.

local strings = import("strings") -- this is Go's strings library

function trim(s)
    return strings.TrimSpace(s)
end

That explains why the Lua creators don’t need to bother with adding these functions, they can be added from whatever language Lua is being executed from.