What does LUA acronym stand for?

The programming language is named Lua, it is officially not a acronym. Lua is a common word meaning Moon in Portuguese. The language is named like this because a previous programming language at PUC (in early development phase) was already named SOL for Simple Object Language. And since SOL means Sun in Portuguese, its successor … Read more

“main” function in Lua?

There’s no “proper” way to do this, since Lua doesn’t really distinguish code by where it came from, they are all just functions. That said, this at least seems to work in Lua 5.1: matthew@silver:~$ cat hybrid.lua if pcall(getfenv, 4) then print(“Library”) else print(“Main file”) end matthew@silver:~$ lua hybrid.lua Main file matthew@silver:~$ lua -lhybrid Library … Read more

Get back the output of os.execute in Lua

If you have io.popen, then this is what I use: function os.capture(cmd, raw) local f = assert(io.popen(cmd, ‘r’)) local s = assert(f:read(‘*a’)) f:close() if raw then return s end s = string.gsub(s, ‘^%s+’, ”) s = string.gsub(s, ‘%s+$’, ”) s = string.gsub(s, ‘[\n\r]+’, ‘ ‘) return s end If you don’t have io.popen, then presumably … Read more

Lua find a key from a value

If you find yourself needing to get the key from the value of a table, consider inverting the table as in function table_invert(t) local s={} for k,v in pairs(t) do s[v]=k end return s end

How to dump a table to console?

If the requirement is “quick and dirty” I’ve found this one useful. Because if the recursion it can print nested tables too. It doesn’t give the prettiest formatting in the output but for such a simple function it’s hard to beat for debugging. function dump(o) if type(o) == ‘table’ then local s=”{ ” for k,v … Read more

ESP8266 NodeMCU Running Out of Heap Memory

There was a problem in the NodeMCU docs with the socket:send example you seem to have based your implementation on. We discussed it and I fixed it. An improved version of your code is this: gpio.mode(3, gpio.OUTPUT) srv = net.createServer(net.TCP, 28800) print(“Server created… \n”) local pinState = 0 srv:listen(80, function(conn) conn:on(“receive”, function(sck, request) local _, … Read more