Lua’s package management system?

There is no standard Lua package management system, but you can try out the following: LuaRocks – contains a rather large number of Lua modules distributed as rocks. Once LuaRocks is installed, the installation is simple: luarocks install desired-package. On Linux/Unix/Mac, this will install into /usr/local/{share,lib}/lua/5.1, where the Lua interpreter looks for modules. LuaDist – … Read more

How to remove spaces from a string in Lua?

It works, you just have to assign the actual result/return value. Use one of the following variations: str = str:gsub(“%s+”, “”) str = string.gsub(str, “%s+”, “”) I use %s+ as there’s no point in replacing an empty match (i.e. there’s no space). This just doesn’t make any sense, so I look for at least one … Read more

current line number in Lua

From Lua using debug.getinfo, e.g., local line = debug.getinfo(1).currentline From C using lua_getinfo (This will return the linenumber inside lua code) lua_Debug ar; lua_getstack(L, 1, &ar); lua_getinfo(L, “nSl”, &ar); int line = ar.currentline http://www.lua.org/manual/5.1/manual.html#lua_getinfo http://www.lua.org/manual/5.1/manual.html#pdf-debug.getinfo

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

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).

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)