Creating standalone Lua executables
Check out for srlua. It does what you need. It’s from one of the Lua authors. On this address there is also pre-compiled Windows binaries, so that would be even easier for you I think.
Check out for srlua. It does what you need. It’s from one of the Lua authors. On this address there is also pre-compiled Windows binaries, so that would be even easier for you I think.
Nope. No difference, except that you can enclose the other inside the ones that you are using. — No difference between these myStr = “Hi!!” myStr=”Hi!!” myStr = [[Hi!!]] — The ‘weird’ way to make a string literal IMO… — Double quotes enclosed in single quotes myStr=”My friend said: “Hi!!”” — Single quotes enclosed in … Read more
Lua indexes tables from 1, unlike C, Java etc. which indexes arrays from 0. That means, that in your table, the valid indexes are: 1, 2, 3, 4. What you are looking for is the following: print( myTable[ math.random( #myTable ) ] ) When called with one argument, math.random(n) returns a random integer from 1 … Read more
This is just guesswork on my part, but: 1. It’s hard to implement this in a single-pass compiler Lua’s bytecode compiler is implemented as a single-pass recursive descent parser that immediately generates code. It does not parse to a separate AST structure and then in a second pass convert that to bytecode. This forces some … Read more
Try function file_exists(name) local f=io.open(name,”r”) if f~=nil then io.close(f) return true else return false end end but note that this code only tests whether the file can be opened for reading.
ipairs() and pairs() are slightly different, as you can see on the manual reference. A less-technical description could be that: ipairs() returns index-value pairs and is mostly used for numeric tables. The non-numeric keys are ignored as a whole, similar to numeric indices less than 1. In addition, gaps in between the indexes lead to … Read more
Use math.fmod(x,y) which does what you want: Returns the remainder of the division of x by y that rounds the quotient towards zero. http://www.lua.org/manual/5.2/manual.html#pdf-math.fmod
I know this question is seven years old, but Lua 5.4 finally brings const to the developers! local a <const> = 42 a = 100500 Will produce an error: lua: tmp.lua:2: attempt to assign to const variable ‘a’ Docs: https://www.lua.org/manual/5.4/manual.html#3.3.7.
The correct way to write this is either local t = { foo = 1, bar = 2} Or, if the keys in your table are not legal identifiers: local t = { [“one key”] = 1, [“another key”] = 2}
Translate all of the Lua source code files to object files and put them in a static library: for f in *.lua; do luajit -b $f `basename $f .lua`.o done ar rcus libmyluafiles.a *.o Then link the libmyluafiles.a library into your main program using -Wl,–whole-archive -lmyluafiles -Wl,–no-whole-archive -Wl,-E. This line forces the linker to include … Read more