Lua print on the same line
Use io.write instead print, which is meant for simple uses, like debugging, anyway.
Use io.write instead print, which is meant for simple uses, like debugging, anyway.
Game engines that use Lua Free unless noted Agen (2D Lua; Windows) Amulet (2D Lua; Window, Linux, Mac, HTML5, iOS) Cafu 3D (3D C++/Lua) Cocos2d-x (2D C++/Lua/JS; Windows, Linux, Mac, iOS, Android, BlackBerry) Codea (2D&3D Lua; iOS (Editor is iOs app); $14.99 USD) Cryengine by Crytek (3D C++/Lua; Windows, Mac) Defold (2D Lua; Windows, Linux, … Read more
local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end Note that you cannot guarantee any order in keyset. If you want the keys in sorted order, then sort keyset with table.sort(keyset).
Overcomplicated answers much? Here is my implementation: function TableConcat(t1,t2) for i=1,#t2 do t1[#t1+1] = t2[i] end return t1 end
Looking at the code of string.format, I don’t see anything that supports boolean values. I guess tostring is the most reasonable option in that case. Example: print(“this is: ” .. tostring(true)) — Prints: this is true
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
There’s a good discussion at Lambda the Ultimate. LuaJIT is very good. Many people have reported impressive speedups on lua-l (the lua mailing list). The speedups are most impressive for pure Lua code; the trace compiler is not as effective when there are lots of calls to C functions in loadable library modules.
Try: name = “^aH^ai” name = name:gsub(“%^a”, “”) See also: http://lua-users.org/wiki/StringLibraryTutorial
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/
That is the length operator: The length operator is denoted by the unary operator #. The length of a string is its number of bytes (that is, the usual meaning of string length when each character is one byte). The length of a table t is defined to be any integer index n such that … Read more