Skip to main content
270 votes
16 answers
455k views

How can I convert a string to an integer in Lua? I have a string like this: a = "10" I would like it to be converted to 10, the number.
David Gomes's user avatar
  • 5,935
263 votes
4 answers
80k views

I am confused about the difference between function calls via . and via : local x = { foo = function(a, b) return a end, bar = function(a,b) return b end } return x.foo(3, 4) -- 3 return x....
Jason S's user avatar
  • 191k
239 votes
21 answers
402k views

I'm having trouble displaying the contents of a table which contains nested tables (n-deep). I'd like to just dump it to std out or the console via a print statement or something quick and dirty but I ...
Cliff's user avatar
  • 11.5k
237 votes
24 answers
489k views

How do I split a string? There doesn't seem to be a built-in function for this.
RCIX's user avatar
  • 39.7k
231 votes
12 answers
263k views

I have been dealing a lot with Lua in the past few months, and I really like most of the features but I'm still missing something among those: Why is there no continue? What workarounds are there for ...
Dant's user avatar
  • 2,311
213 votes
11 answers
401k views

Sounds like a "let me google it for you" question, but somehow I can't find an answer. The Lua # operator only counts entries with integer keys, and so does table.getn: tbl = {} tbl["test"] = 47 tbl[...
Roman Starkov's user avatar
192 votes
9 answers
125k views

Given an array of x,y points, how do I sort the points of this array in clockwise order (around their overall average center point)? My goal is to pass the points to a line-creation function to end up ...
Philipp Lenssen's user avatar
186 votes
9 answers
105k views

I don't understand the rationale behind the decision of this part of Lua. Why does indexing start at 1? I have read (as many others did) this great paper. It seems to me a strange corner of a language ...
Khaled Alshaya's user avatar
171 votes
5 answers
325k views

Is there a method for checking if a table contains a value ? I have my own (naive) function, but I was wondering if something "official" exists for that ? Or something more efficient... function ...
Wookai's user avatar
  • 21.9k
169 votes
8 answers
163k views

Is there anyway to use inline conditions in Lua? Such as: print("blah: " .. (a == true ? "blah" : "nahblah"))
Softnux's user avatar
  • 2,740
163 votes
7 answers
137k views

What's the most efficient way to determine if a table is empty (that is, currently contains neither array-style values nor dict-style values)? Currently, I'm using next(): if not next(myTable) then ...
Amber's user avatar
  • 532k
150 votes
2 answers
178k views

In a for loop, what is the difference between looping with pairs() versus ipairs()? The Programming in Lua book mentions both, however, both appear to generate similar outputs as shown below: Using ...
user avatar
136 votes
2 answers
158k views

I have a lua table that I use as a hashmap, ie with string keys : local map = { foo = 1, bar = 2 } I would like to "pop" an element of this table identified by its key. There is a table.remove() ...
Wookai's user avatar
  • 21.9k
130 votes
6 answers
146k views

I have a string in Lua and want to iterate individual characters in it. But no code I've tried works and the official manual only shows how to find and replace substrings :( str = "abcd" for char in ...
grigoryvp's user avatar
  • 43k
127 votes
8 answers
50k views

I simply love JavaScript. It's so elegant. So, recently I have played with Lua via the löve2d framework (nice!) - and I think Lua is also great. They way I see it, those two languages are very similar....
stefs's user avatar
  • 18.5k

15 30 50 per page
1
2 3 4 5
1533