Jump to content




Lua: What would you change?


  • You cannot reply to this topic
83 replies to this topic

#81 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 21 September 2014 - 07:58 AM

View PostFerdi265, on 27 August 2014 - 04:41 PM, said:

sci4me said:

Functions with different parameters but the same name!!! Seriously, WHY IS THIS NOT A THING?
Because functions are values. having two functions with the same name is like storing two functions in one variable, which isn't quite possible. (also lua wouldn't know what to call if you did

It actually IS possible believe it or not. You use the same solution as I suggested above to replace all function creations with a table of all functions of the same name.
The table has a metatable __call that when called checks the type of all arguments and selects the best function from the functions stored in the table.
You also need a metatable extending code so you can make the table appear to be a function etc etc

#82 ElvishJerricco

  • Members
  • 803 posts

Posted 21 September 2014 - 05:49 PM

View PostKaoS, on 21 September 2014 - 07:58 AM, said:

View PostFerdi265, on 27 August 2014 - 04:41 PM, said:

sci4me said:

Functions with different parameters but the same name!!! Seriously, WHY IS THIS NOT A THING?
Because functions are values. having two functions with the same name is like storing two functions in one variable, which isn't quite possible. (also lua wouldn't know what to call if you did

It actually IS possible believe it or not. You use the same solution as I suggested above to replace all function creations with a table of all functions of the same name.
The table has a metatable __call that when called checks the type of all arguments and selects the best function from the functions stored in the table.
You also need a metatable extending code so you can make the table appear to be a function etc etc

This seems extremely inefficient. Calls are fast. Searching tables is slow. Other languages handle overloading by knowing at compile time what exactly needs to be called. Overloading in Lua just can't be done efficiently. I see no reason to let my code do so much work when I could just have a differently named function.

#83 Agent Silence

  • Members
  • 319 posts
  • Location[string "FindMe"]:23143: bad argument #1 to 'returnPos' (vector expected, got nil)

Posted 22 September 2014 - 05:28 PM

Defining variables after a block as in
while true do
print(a)
end
a = "This variable was executed after the loop


#84 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 22 September 2014 - 06:44 PM

What benefit could that possibly give you? That would break... everything.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users