An unofficial, read-only Hacker News reader.

Lua for data representation (2025) (opens external site)

104 points by vinhnx 4 days ago | citrons.xyz | 61 comments on HN

View full thread · View on Hacker News

Comment thread (5)

  1. It’s also pretty nice that a verb plus a table is implicitly a function call. This means you can easily do things that seem to be types:

      m = Menagerie {
        Dog { tail, ears, snout=long },
        Cat { you, get, the=idea },
        table.unpack(ark),
      }
    Replies (2)
    1. This syntax is inherited from one of Lua's predecessors, Sol, for compatibility, and in Sol, it actually means types!

      There are a couple of snippets here that refer to it (search for @track):

      https://www.lua.org/history.html

    2. You can go further and even register your actual C++ types (e.g. with sol2), which removes lots of extra parsing steps:

          pos = Point(2.5, 8.9)
          size = Size(4, 5)
          opacity = 0.5
          color = Color(0.5, 0.2, 0.1)
      Replies (2)
      1. C types as well (with LuaJIT.). Building metaclasses around SDL objects and adding a tostring function to they can all be printed, for instance. It's so much easier to build a C API in Lua than it is to build a Lua API in C.
      2. You don’t need anything special to do that, you can just export Lua functions that return userdata