Live data from Hacker News

LÖVE: 2D Game Framework for Lua

github.com

201–210 of 229 posts

Re: LÖVE: 2D Game Framework for Lua

#201

Earlier quoted context omitted.

There is nothing stopping you from doing someArray[0] = "the first item", you know. For me, the table is extremely powerful. I like it that it can be used as a sparse array, a hash, a vector, whatever. Of course one must know, at heart, the difference between pairs() and ipairs() and what it means for your data, though ..

> There is nothing stopping you from doing someArray[0] = "the first item", you know. Yes, there is: local l = {[0] = 'a', [1] = 'b', [2] = 'c'} for i, c in ipairs(l) do print(i, c) end This will only print the last two pairs. Lua is 1-indexed, end of story. You can store values at index zero, but it's no different than storing values at index -1 or index 'lolrofl'. It does not exist in the array-part of the table as…

If you're going to use a table as an array, use it as an array:

    local l = {[0] = 'a', [1] = 'b', [2] = 'c'}
    for i = 0,#l do
      print(l[i])
    end

    .. prints:

    a
    b
    c
Lua haters usually don't get past their misunderstanding of tables, but its really quite unfair on the language and those who have used it quite well to do big things ..

Re: LÖVE: 2D Game Framework for Lua

#202
post #188

Earlier quoted context omitted.

There is nothing stopping you from doing someArray[0] = "the first item", you know. For me, the table is extremely powerful. I like it that it can be used as a sparse array, a hash, a vector, whatever. Of course one must know, at heart, the difference between pairs() and ipairs() and what it means for your data, though ..

> For me, the table is extremely powerful. I like it that it can be used as a sparse array, a hash, a vector, whatever. Of course one must know, at heart, the difference between pairs() and ipairs() and what it means for your data, though .. So, as someone only very peripherally familiar with Lua, can someone please explain the table thing to me? I've heard Lua fans gush that Lua is tables all the way down, except it…

Tables are kinda-sorta hashes that can hold anything, not unlike JavaScript objects. The array use case is just a table with automatically assigned numeric keys.

Re: LÖVE: 2D Game Framework for Lua

#203
post #7

One of the biggest recent indie hits, Balatro, was made in Löve! I really like it, the developer experience is so smooth for beginners, just drag a zip onto the exe and it starts. And the APIs are simple enough to memorize while allowing pretty cool rendering stuff.

Balatro ships with the entire unobfuscated Lua source by the way. I once checked if the odds stated on a card were implemented wrong. Turns out no, the code checks out, I'm just that unlucky.

come on you can blame whatever the program is using for randomness still

Re: LÖVE: 2D Game Framework for Lua

#204
post #126

Earlier quoted context omitted.

What were your (main) problems with Kodi? AFAIK it is written in C++ with Python plugins. Electron would be (on the face) a downgrade yes. But how is a Lua app much smoother? (My personal pet peeve is that Kodi still doesn't know how to minimize CPU consumption when one is doing nothing on the UI. It should just stop rendering. This means I have to turn Kodi off on my HTPC+server setup to stop it from pushing my CPU…

Kodi is super complex. The last straw was me wanting to launch Dolphin games from the UI and not being able to figure it out. My custom media center is basically just a glorified 10ft-UI file browser. Opens media files in mpv (with some extra GUI to download subtitles and select audio tracks), Wii games in Dolphin, runs shell scripts (I have ones launch Steam Link etc.) I realize that this might be a case of "simplif…

I would like you to release this please

Re: LÖVE: 2D Game Framework for Lua

#205
post #28

Am I really the first one to mention pico8 in this thread? Anyway, pico8 is another option that has a bit different spin, but you also implement the games in Lua :)

antirez' LOAD81 never gets enough love in these discussions even though it is simply awesome: https://github.com/antirez/load81 Anyone looking at Lua/SDL/game engines would learn a lot from antirez' fun little afternoon project ..

People talk about the stuff they use, and there are _a lot_ of fantasy consoles.

https://github.com/paladin-t/fantasy

Re: LÖVE: 2D Game Framework for Lua

#206

Earlier quoted context omitted.

I'm curious as to how you came to that conclusion. Did you run any tests, or is it just a general observation? What's your computer hardware like? This isn't an accusation of anything, I promise I'm genuinely curious.

I've not done proper scientific comparisons, but had to reimplement some games as websites to make them reliably perform on Raspberry Pi's we used embedded. This is a bit of an apples to oranges scenario, because the algorithm and architecture is not exactly the same, despite the game functioning identical. The main weak points of LÖVE that we hit were mainly around embedded video playback though, which is probably v…

I dunno if this is what you were seeing, but LuaJIT has some serious performance issues on ARM.

https://love2d.org/forums/viewtopic.php?t=94760

It's unfortunate as Love2D is generally VERY snappy on x86. I used it on a 300MHz laptop back in the day.

Re: LÖVE: 2D Game Framework for Lua

#207
post #188

Earlier quoted context omitted.

There is nothing stopping you from doing someArray[0] = "the first item", you know. For me, the table is extremely powerful. I like it that it can be used as a sparse array, a hash, a vector, whatever. Of course one must know, at heart, the difference between pairs() and ipairs() and what it means for your data, though ..

> For me, the table is extremely powerful. I like it that it can be used as a sparse array, a hash, a vector, whatever. Of course one must know, at heart, the difference between pairs() and ipairs() and what it means for your data, though .. So, as someone only very peripherally familiar with Lua, can someone please explain the table thing to me? I've heard Lua fans gush that Lua is tables all the way down, except it…

It's not really tables all the way down - Lua has datatypes like nil, boolean, number, string, table, userdata + lightuserdata, functions, coroutines. I think that's the entire list, actually.

So a table is a hashtable. Just about anything can be a key to the hash - a number, a string, a boolean, another table, a userdata. I can't recall if functions and coroutines can be keys but I suspect they could. I definitely know that nil can't be an index.

In Lua - all iterators are implemented as a function + state + current key. When you write "for x in (whatever)", that (whatever) is really a function call like func(state,key). Lua calls it repeatedly to traverse the loop.

Lua will take the first returned value and use it as the new key in the next call to func(). Once the function returns nil as the first value (or just returns no values) - the loop stops.

There are two functions - pairs and ipairs - that really just return the built-in next function with a starting key. pairs returns (lua's next(), the table, nil), and ipairs returns (next(), the table, 0).

(there's a bit more to it than that and some under-the-hood changes between Lua versions but we'll just go with that explanation).

Lua repeatedly calls that next() function with the table and previous key.

Say you had an array like table like { [1] = some_value, [2] = another_value }.

When you write something like "for i,v in ipairs(a_table)" that roughly expands to:

  * pairs() returns next(), the table, 0. 
  * Lua calls next(table, 0) and next returns (1, some_value)
  * Lua calls next(table, 1) and next returns (2, another_value)
  * Lua calls next(table, 2) and next returns nil.
So - when is a table an array?

When you can iterate through it with sequential, integer keys.

Note - you don't necessarily need to use ipairs to iterate. Lua also has a numerical "for" loop so you could do that. Or - if you want to start your arrays at 0 instead of one you can write your own ipairs() like function in just a few lines of code. Observe:

  local zpair_it = function(table, key)
    key = key + 1
    if table[key] then
      return key, table[key]
    end
  end

  local zpairs = function(table)
    return zpair_it, table, -1
  end

  local tab = { [0] = 'yay', [1] = 'huzzah' }
  for i,v in zpairs(tab) do
    print(i,v)
  end

There - now instead of using ipairs(), you can use zpairs() with zero-based indexes.

As far as using like objects, that's getting into metatables and stuff but - basically lua has a syntactical sugar to make object-orientation nice.

If you write "obj:func()" - that's the same as writing "obj.func(obj)" - assuming "obj" is a table, Lua will fetch the "func" key from the table, then call it as a function with "obj" as the first argument (this can be referred to as self within your function definition).

If Lua tries to fetch "func" from your table and it doesn't exist - it will check to see if your table has a metatable defined with an __index metamethod (or table) and pull func from that. So - your table could just have your object's actual state data on it, and functions are referenced in a separate metatable.

Observe:

  local dog_methods = {
    bark = function(self)
      print("bark bark I'm a",self.breed)
    end
  }

  local dog_metatable = {
    __index = dog_methods
  }

  local huskie = setmetatable({
    breed = 'huskie'
  }, dog_metatable)

  local collie = setmetatable({
    breed = 'collie'
  }, dog_metatable)

  huskie:bark()
  collie:bark()

huskie:bark() is equivlanet to huskie.bark(huskie). bark doesn't actually exist on huskie, but huskie has a metatable with an __index table where bark is defined. So the function call is really more like dog_methods.bark(huskie).

Anyways wow that was a lot. Highly recommend going through the Lua manual. It's not a long read.

Re: LÖVE: 2D Game Framework for Lua

#208
post #166

Earlier quoted context omitted.

Good news: the universe is written in LISP. Bad news: with no comments.

You can ask AI to comment an entire code base now in as much detail as you need.

Comments explaining what the code does, which is what an LLM could answer, are basically useless comments. Comments that describes why the code is how it is, is a bit more valuable, but also something LLMs cannot really reliably infer by just looking at the code.

Re: LÖVE: 2D Game Framework for Lua

#209

Earlier quoted context omitted.

Small stdlib, “implement it yourself” philosophy to even things like classes, diverging language versions and fragmentation (a lot of people don’t like any of the post 5.1 changes), bad tooling and editor support, dynamic duck typed language with no type hints

If it were about making a choice of which web framework to use on the server, obviously you wouldn't want to use Lua. But if it is about using it as an embedded language. you want just enough language to get you started and be able to tweak controls. so that the embedded language itself doesn't take up unnecessary space, on its own. It's a design choice to have a language as small as possible while still offering coo…

[flagged]

Re: LÖVE: 2D Game Framework for Lua

#210

Earlier quoted context omitted.

I've not done proper scientific comparisons, but had to reimplement some games as websites to make them reliably perform on Raspberry Pi's we used embedded. This is a bit of an apples to oranges scenario, because the algorithm and architecture is not exactly the same, despite the game functioning identical. The main weak points of LÖVE that we hit were mainly around embedded video playback though, which is probably v…

I dunno if this is what you were seeing, but LuaJIT has some serious performance issues on ARM. https://love2d.org/forums/viewtopic.php?t=94760 It's unfortunate as Love2D is generally VERY snappy on x86. I used it on a 300MHz laptop back in the day.

LuaJIT was originally made with some x86 assembly wizardry so I'm not surprised to hear that the ARM version is worse.
Post reply on HN