31

I know it's not done yet but OOOOOH boy I'm proud already.

Writing a JSON parser in Lua and MMMM it can parse arrays! It converts to valid Lua types, respects the different quotation marks, works with nested objects, and even is fault-tolerant to a degree (ignoring most invalid syntax)

Here's the JSON array I wrote to test, the call to my function, and another call to another function I wrote to pretty print the result. You can see the types are correctly parsed, and the indentation shows the nested structure! (You can see the auto-key re-start at 1)

Very proud. Just gotta make it work for key/value objects (curly bracket bois) and I'm golden! (Easier said than done. Also it's 3am so fuck, dude)

Comments
  • 3
    Man this is awesome, I remember I had something similar to parse mathematic expression,

    I had a lexer to parse a string into words/gramma, and from there build the expression tree, etc..
  • 3
    @xzvf

    A) Thought it would be fun

    B) A large, complete Lua library sort of project

    @nam17887 That's on the list!
  • 2
    Nice another one that uses lua :D
  • 2
    If I may, why use Lua? Is it something you prefer? Just curious, good job on what you’ve got so far😄
  • 1
    Love Lua. Used it while making Garry's Mod servers.
  • 1
    @Bubbles Favorite language

    @SauceBoss That's exactly what it is! There's also a lot of c and c++ writing with lua
  • 1
    @AlgoRythm I’m curious, why is it your favorite language? I’m guessing you use C or C++ a lot if that’s the case right?
  • 1
    @Bubbles Yes, I love c and c++

    The Syntax of Lua is so wonderful. It reads like English so much. No silly brackets for scope. One-liners don't look awful, they look good:

    while true do print end

    if true then print end

    It's written in clean C, so you can compile it anywhere pretty much. You can import dll and so files, provided they were specifically written for Lua, which means this language can pretty much do anything c can do with a little conversion work.

    It's quick, handles large amounts of data well, and has a small footprint on the system.

    It supports operator overloading (In a way, see metatables), OOP (again, metatables) and only has a few basic types (Pretty much number, string, function, and boolean)

    Everything is just so clean and functional

    The only blemish is that arrays start at 1. Everything else is great.
  • 1
    @AlgoRythm I’ll have to look into it for my C/C++ projects
  • 0
    @Bubbles It's great because you can really easily incorporate it into them without needing to install Lua on the client machine. It's the best embedded language.

    And, as an unpopular opinion, arrays starting at 1 makes more sense when you aren't dealing with raw memory. Makes it easier to deal with strings and reduces the off-by-one errors.
  • 1
    @AlgoRythm yeah but it not starting at 0 makes me wanna hurl
  • 1
    @Bubbles You're such a stereotype XD
  • 1
    @AlgoRythm it’s the only language I’ve considered learning that starts at 1
  • 1
    @Bubbles I've already done a big ole rant about the "1" thing but I wanna make a video about it. Explain why arrays start at 0 and why dynamic typed languages don't have arrays and why starting at 1 is non-standard but still correct and the advantages and disadvantages of it.

    I think it's an interesting topic and it sucks when people just automatically see it as a bad thing.
  • 1
    @AlgoRythm interesting, I’d love to hear about it
Add Comment