How to dump a table to console?

If the requirement is “quick and dirty” I’ve found this one useful. Because of 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

Lua math.random not working

You need to run math.randomseed() once before using math.random(), like this: math.randomseed(os.time()) One possible problem is that the first number may not be so “randomized” in some platforms. So a better solution is to pop some random number before using them for real: math.randomseed(os.time()) math.random(); math.random(); math.random() Reference: Lua Math Library

How can I embed Lua in Java?

LuaJ is easy to embed in Java. I did have to change a few lines of their source to get it to work how I expected (it didn’t require the IO library automatically). http://sourceforge.net/projects/luaj/

Safely remove items from an array table while iterating

the general case of iterating over an array and removing random items from the middle while continuing to iterate If you’re iterating front-to-back, when you remove element N, the next element in your iteration (N+1) gets shifted down into that position. If you increment your iteration variable (as ipairs does), you’ll skip that element. There … Read more

How to fix “NSURLErrorDomain error code -999” in iOS

The error has been documented on the Mac Developer Library(iOS docs) The concerned segment from the documentation will be: URL Loading System Error Codes These values are returned as the error code property of an NSError object with the domain “NSURLErrorDomain”. enum { NSURLErrorUnknown = -1, NSURLErrorCancelled = -999, NSURLErrorBadURL = -1000, NSURLErrorTimedOut = -1001, … Read more