Live data from Hacker News

I open sourced my game along with a tutorial on how to make it using Lua

github.com

91–96 of 96 posts

Re: I open sourced my game along with a tutorial on how to make it using Lua

#91
post #82
post #75

Earlier quoted context omitted.

The tools are all written in C and use microui[1] for the UI. The games are typically written in LÖVE with the exception of SCANLINE which uses Nim [1] https://github.com/rxi/microui

First time I heard about 'lite'. I have to say the first impression is really great. Fast and smooth. Nice work!

Thanks!

Re: I open sourced my game along with a tutorial on how to make it using Lua

#92
post #84

Earlier quoted context omitted.

Yet, none of those are consistent with that on non-string objects: To get the last object of an array in JS is: arr = [1, 2, 3] arr[arr.length - 1] To get the last object of an array in Python is: arr = [1, 2, 3] arr[len(arr) - 1] To get the last object of an array in Lua is: arr = {1, 2, 3} arr[#arr]

There is a difference between order and offset , both consistent and makes sense. We use both models in everyday life. Examples of offset are ruler (marks 0, 1, ...), time offset (this hour, next hour, ..), age (newborn, one year, two years), count (last, last but one). That's reflected in our languages [1]. > non-string objects There is no difference between array and string access in ruby, python, js. There are bet…

> I mentioned your comment is wrong. I do not know why you are turning it into 0-indexing vs 1-indexing, looks like changing topic for me.

... That's exactly where this topic started:

> 1-index kept throwing me off though

---

> There is no difference between array and string access in ruby, python, js.

There's no difference in Lua either:

    s:sub(1, 1)
    tbl:select(1, 1)
But it doesn't use offset, and I find that more useful for preventing off-by-one errors.

Re: I open sourced my game along with a tutorial on how to make it using Lua

#93
post #92

Earlier quoted context omitted.

There is a difference between order and offset , both consistent and makes sense. We use both models in everyday life. Examples of offset are ruler (marks 0, 1, ...), time offset (this hour, next hour, ..), age (newborn, one year, two years), count (last, last but one). That's reflected in our languages [1]. > non-string objects There is no difference between array and string access in ruby, python, js. There are bet…

> I mentioned your comment is wrong. I do not know why you are turning it into 0-indexing vs 1-indexing, looks like changing topic for me. ... That's exactly where this topic started: > 1-index kept throwing me off though --- > There is no difference between array and string access in ruby, python, js. There's no difference in Lua either: s:sub(1, 1) tbl:select(1, 1) But it doesn't use offset, and I find that more us…

I am to used to 0-indexing to judge. If it is not clear already - I am not going to participate in who is better. My thread is

>>>> a string will always be:

    s:sub(1, #s)
>>> In a language that used the half-open interval convention we would end up with:

    s:sub(0, #s)
>> You would end up with:

     s:sub(0, #s - 1)
> That would be strange, in Ruby

    s[0, s.length]
Your argument against 0-index is just plain wrong. No one creates such API. It would be to awkward - either #s should be `length + 1` or `sub` should expect `length + 1`.

----

>>>> Once you get used to it, ... you don't need math when grabbing a range.

I assure you once you get used to 0-indexing there is no need for math when grabbing a range

    s[0..s.length] # that is identity through range in ruby 
----

>>>>> 1-index kept throwing me off though

>>>> it does help prevent a whole bunch of off by one errors

You claim superiority, it is not. I can't remember such errors in my life. It may be easier to describe to children but I doubt it. My first encounter with 0-indexing was with ruler - "why it starts with 0?" - pre-school. I can claim 0-index is natural. I would not.

There is no better model just "happy accidents".

Re: I open sourced my game along with a tutorial on how to make it using Lua

#94

Earlier quoted context omitted.

The main problem with that decision is that every discussion having anything to do with Lua always devolves into repetitive bikeshedding about the 1-indexing.

I think the main problem with 1-indexing is that it makes some formulas that depend on the length of an array more complicated. Not a huge problem, but it's kind of annoying.

Off by ones happen with 0-based too (to me at least, at "write the new codez" stage). What languages are really missing is some stdlib for hiding these calculations under easily understandable names like nthfromend, nfromto, revidx, last, etc. Too much of n-1, n-i-1, -i-1, b-a+1, 0/1-based are simply two degenerate around-off-by-one cases of working at general n-based offset, since both 0 and 1 are the most common results of off-by-one.

Re: I open sourced my game along with a tutorial on how to make it using Lua

#95

Earlier quoted context omitted.

It replaces the standard [0,len()) with an [1,len()], though, which correspondingly makes other tasks easier. Plus it matches normal mathematical vector indexing. In the end, in a language where you aren't doing pointer arithmetic, the sides are pretty even. We just tend to side with tradition, because it's easier to.

I found it uncomfortable when drawing on screen: y = margin + (i - 1) * lineheight

  y = 1 + ...
if y is 1-based too (which feels even more uncomfortable). But it would be nice to have such functions out if the box:

  canvas.linear_index(x, y, stride)
  vbox.y1_for(margin, spacing, height, i)
  vbox.y2_for(margin, spacing, height, i)
And then you have "integer at the center of a pixel" vs "integer at the top-left of a pixel" differences, which should be taken into account by these functions too. Stroke 1: y+0.5, y+height-1. Stroke 2: y+1, y+height-2. Fill: y, y+height.

Pixel geometry is hard on its own.

Re: I open sourced my game along with a tutorial on how to make it using Lua

#96

I've never heard of Lua, but now that I am looking at it, it seems very friendly. Love how they call things what they are, for example `local` is just a local variable, or `repeat X until Y` for a loop. It's a joy to see, to be honest.

There’s a successor to Lua in the works called Mun: https://mun-lang.org/ It is written in Rust and aims to be 100% hot-reloadable.

I'm not sure if a statically typed AOT compiled language with no fibers can be a successor to Lua.
Post reply on HN