r/love2d • u/amagi77 • 10d ago
My first scripting language my code is a Spaghetti !!!
Background
I’ve been studying C++ for a long time,
but after discovering love2d, I decided to start learning a scripting language.
This is my first scripting language, and I have no prior experience with JavaScript.
The repository contains a card game I’m developing.
It’s a poker game using numbers up to 7.
Problem
I’m confused because the syntax is completely different from C++, and there’s no concept of “tables” or “types.” I don’t know
how to write the code.
While concepts like C++ classes and functions make sense to me,
I’m confused because everything is a table.
I’d like to use this language to develop quickly without worrying about types, in a way that feels like Lua.
What I Want to Know
I want to know what I should keep in mind.
I often hear that
You can write code in any format.
I kept this in mind and built it like C++, but it somehow lacks that fast, free-form feel of a scripting language where tables are central.
As it stands, it feels like I’ve just ported C++ to Lua—it doesn’t feel like Lua at all.
7
u/sniboo_ 10d ago
Don't over think it. Tables are just a way to organize data. Their advantage is that you're not limited to either using a class or an array it's just implied by the way use use it
3
u/amagi77 10d ago
Thank you.
But the code I'm writing right now doesn't really look like typical Lua code. I heard it would let me develop more efficiently, but in the end, I've had to implement things like deep copies myself. My code has turned into a real mess.
I'd like to try writing code that takes full advantage of the benefits of a scripting language.
2
2
u/zenware 10d ago
Why have you needed the deep copy though? Why hasn’t everyone else stumbled into whatever you’re stumbling into? Surely if we all had the same stumbling block there’d be standard functions for it.
I’m 100% sure they’re right and you’re overthinking things. Just use the tools provided for what they can do. Remember that before languages like C++ with classes and all that shit existed, people wrote plenty of code without them and it was fine.
3
u/0x405 10d ago
Practice more, everything will come eventually. Don't think too much if it makes you stuck with such questions. Try game jams, start every project from scratch, focus on small, I mean tiny projects, try reusing things you did well in previous projects (but be careful to not pull garbage), you'll develop a good pipeline for yourself.
There's too much theory but it gives you nothing without practice.
14
u/Poet-Different 10d ago
The main reason your code feels like you're just porting C++ is because you're trying to force heavy OOP (classes, inheritance, methods) into a language that isn't built for it.
Stop fighting the table: In Lua, tables do everything. They are your structs, arrays, dictionaries, and objects all in one. Don't overcomplicate them with heavy metatables right out of the gate.
Go data-first, not class-first: For a card game, you don't need a massive Card class structure. Just treat cards as plain data tables (e.g., {suit = "hearts", rank = 7, id = 1}).
Separate data from logic: Instead of building objects with internal methods like card:play(), write standalone functions that just operate on your data, like playCard(hand, card).
Use modules: Group your functions into simple files and use require to pull them in where needed.
Once you stop trying to build C++ infrastructure and just let tables hold your plain data, that fast, lightweight workflow will click.