of     1   

ArbiterOfDeath
#123668765Tuesday, January 21, 2014 3:19 AM GMT

I've made some crazy implementations of classes in Lua, but nothing like I'm planning to make. Below is some sample code. This will be ran in Lua and callable in Lua. Let me know what you think about the syntax, and how I should improve it. Yes, it does comply with Lua's syntax. Here is some features that could be included: -Type checking -Classes -Inheritance -Interfaces -Abstract classes -Access modifiers -Polymorphism Here is the sample code. You might want to put it into studio and pace it out. --------------------------------------------------- require(Workspace["Phalanx Lua"]) public:interface "Accounts"{ public:method "addAccount" (); override.public:method "addAccount" (int "accountID"); public:method "removeAccount" (int "accountID"); }; public:class "Bank" impliments "Accounts"{ private:property "accounts" {}; private:method "changeBallance" (int "accountID", int "amount"){ variable "account" (accounts[accountID]); account:equal (nil) { exit "There is no account with that id."; }; (account - amount):less_than (0) { exit "There is not enough money in that account."; }; accounts[accountID]:set (amount); }; public:method "withdraw" (int "accountID", int "amount"){ exit (changeBallance(accountID, -amount)) }; public:method "deposite" (int "accountID", int "amount"){ exit (changeBallance(accountID, amount)) }; public:method "addAccount" (){ variable "accountID" (#accounts + 1); accounts[accountID]:set (0); exit (accountID); }; override.public:method "addAccount" (int "accountID"){ (accounts[accountID]):not_equal (nil){ exit "There is already an account with that id." }; accounts[accountID]:set (0); exit (accountID); }; public:method "removeAccount" (int "accountID"){ variable "account" (accounts[accountID]); account:equal (nil) { exit "There is no account with that id."; }; accounts[accountID]:set (nil); exit (accountID); }; }; local bank = new "Bank" local accountID = bank:addAccount() bank:deposite(accountID, 999999999) --I'm rich!
Alyte
#123681561Tuesday, January 21, 2014 6:54 AM GMT

NO NO YUCK YOU'RE OBVIOUSLY TRYING TO RUN AWAY FROM LUA!!!!
Alyte
#123681576Tuesday, January 21, 2014 6:55 AM GMT

COME BACK HERE CHILD LET ME SPANK YOUR BOTTOM
ArbiterOfDeath
#123681631Tuesday, January 21, 2014 6:57 AM GMT

Haha, I'm guessing you don't like C++ either.
CrossArms1
#123682996Tuesday, January 21, 2014 7:51 AM GMT

"phalanx" I just couldn't stop thinking of programmers wearing hoplite armour carrying 6-metre long spears and forming a phalanx with their shields having a lua logo painted on them
ArbiterOfDeath
#123683069Tuesday, January 21, 2014 7:54 AM GMT

Yeah. I named it that because of the type checking that's included. It takes the difficulty out of defensive programming.
Charl3s7
#123685675Tuesday, January 21, 2014 10:47 AM GMT

that looks incredibly messy
TheLuaWeaver
#123690805Tuesday, January 21, 2014 2:39 PM GMT

If you want to program like you do in C++ with Lua, that means you're doing it wrong. That is a horrible pollution of the global environment, and you're trying to introduce strong and static typing to weak and dynamic typing. This shows that as a programmer, you haven't fully matured. Use prototypes, not classes. That's more of "The Lua Way". Prototypes are easy-to-do and are a more traditional Lua method for OO. It keeps it small, it keeps it minimal, and in fact, prototypes are more suited for weak/dynamic/duck typing than classes. Heil prototypes. ~LuaWeaver; Programmer, gamer, developer.
Alyte
#123697756Tuesday, January 21, 2014 5:33 PM GMT

Basically, Lua is a scripting language, so don't try to turn it into C++. You'll only end up making your code look horrible and your execution time will be maybe 3x slower, especially with those statically typed variable attempt...
Alyte
#123697851Tuesday, January 21, 2014 5:35 PM GMT

However, it's great that you're making a more complicated OO library than most of the others out there. Just embrace the fact that Lua is a scripting language, and don't over-do it, k?
WarrioR2MasteR
#123698728Tuesday, January 21, 2014 5:51 PM GMT

inb4alldynamiclanguagesturnstatic
MettaurSp
#123717515Tuesday, January 21, 2014 10:27 PM GMT

Embrace dem Luas: http://www.roblox.com/Forum/ShowPost.aspx?PostID=123360204 Doesn't stray too far and over complicate things too much. The code I made for the setup is messy itself, but it cleans it up in the end. All the method calls you want to do make it look way too messy. Speaking of my OO thingy, Ima go make some fixes to it that I made in the past day.
TheLuaWeaver
#123748121Wednesday, January 22, 2014 3:43 AM GMT

>However, it's great that you're making a more complicated OO library than most of the others out there. I once made a really messy thing with newproxy stuff, but it turned into a mess. You can still find it if you know where to look. ~LuaWeaver; Programmer, gamer, developer.
MettaurSp
#123748516Wednesday, January 22, 2014 3:48 AM GMT

cleans up the rest of the code in the end* o3o Lack of specifics lol
CrossArms1
#123759439Wednesday, January 22, 2014 7:28 AM GMT

I will admit right off the bat that I am a total newbie at programming in general. But from what I read, it just looks like you're trying to make Lua more like C++. Surely, as Lua is meant to be a scripting language, this is a bad idea? I will also admit I have no idea what "defensive programming" is.
Charl3s7
#123836452Thursday, January 23, 2014 8:40 AM GMT

"Defensive programming" is used to describe practices where you assume that every bit of code you write can be hacked, making you write tons of error catching.
MrJoeyJoeJoey
#123851019Thursday, January 23, 2014 6:03 PM GMT

When I saw "The Lua Way" I instantly thought of the gray beards yelling code at you and making do weird things.

    of     1