Check if array contains specific value

Lua doesn’t have strict arrays like other languages – it only has hash tables. Tables in Lua are considered array-like when their indices are numerical and densely packed, leaving no gaps. The indices in the following table would be 1, 2, 3, 4. local t = {‘a’, ‘b’, ‘c’, ‘d’} When you have an array-like … Read more

Solving random crashes

Try Valgrind (it’s free, open-source): The Valgrind distribution currently includes six production-quality tools: a memory error detector, two thread error detectors, a cache and branch-prediction profiler, a call-graph generating cache profiler, and a heap profiler. It also includes two experimental tools: a heap/stack/global array overrun detector, and a SimPoint basic block vector generator. It runs … Read more

Lua need to split at comma

Try this str=”cat,dog” for word in string.gmatch(str, ‘([^,]+)’) do print(word) end ‘[^,]’ means “everything but the comma, the + sign means “one or more characters”. The parenthesis create a capture (not really needed in this case).