Posted 30 April 2016 - 12:03 AM
A long time passed since I posted something useful on here. But today I present you my very own implementation of function overloading. I know this already exists and stuff, but it was a nice thing to do and I learned some stuff from it :3
Although you could do all this using many if clauses in one function this looks much cleaner in my opinion.
It features a (IMO) neat syntax. The only drawback is that the function is bound to a table.
Without talking too much, let's look at an example:
I hope this example is self-explanatory.
For everyone interested, here is the source.
Greetings,
~H4X0RZ
Although you could do all this using many if clauses in one function this looks much cleaner in my opinion.
It features a (IMO) neat syntax. The only drawback is that the function is bound to a table.
Without talking too much, let's look at an example:
local overload = dofile("path/to/overload.lua")
overload "example" (
function(str)
print("Hello"..str)
end
) {"string"}
overload.example(", world!")
--> Hello, world!
(yes, this is valid lua syntax)I hope this example is self-explanatory.
For everyone interested, here is the source.
Greetings,
~H4X0RZ
Edited on 03 July 2016 - 07:50 PM