Jump to content




Lua: What would you change?


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

#61 Shazz

  • Members
  • 175 posts

Posted 18 April 2014 - 06:56 PM

View PostMKlegoman357, on 16 April 2014 - 09:52 PM, said:

View Posttheoriginalbit, on 07 April 2014 - 03:38 AM, said:

of course there are always solutions, my point of this was to have it NATIVE not require us to implement us something.

This is native, you're not implementing anything. This is the way to do forward declarations in Lua.
Unless he was implying that all local functions should be forwarded automatically which doesn't make sense because you don't always want that and as Kingdaro pointed out, all functions are essentially variables so that would cause problems.

#62 CCNerd a.k.a CCNoob

  • Banned
  • 14 posts

Posted 15 July 2014 - 07:44 AM

Goto in lua 5.1

#63 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 16 July 2014 - 07:09 AM

View PostCCNerd a.k.a CCNoob, on 15 July 2014 - 07:44 AM, said:

Goto in lua 5.1

No. Please, please no. I know several people who started programming with CC and the last thing we need is to bring in another generation of goto users (BASIC anyone?).I know that deep down in the guts of the machine, goto (or branching as it is known (I think)) is how ifs, whiles and any conditional are evaluated, but that isn't the point - you just end up getting spaghetti code. I can't think of a situation when goto is more useful and sensible than functions.

#64 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 16 July 2014 - 07:22 AM

I can - every time I want to build a great big nested structure and escape from it, I have to lump the whole thing into a function to do so (via return), or else it's a matter of checking a ton of conditionals until I've extricated myself from the how-ever-many blocks I've buried myself in. I dislike making function calls unless it's to re-run repetitive code chunks (as it's redundant), and goto would solve that problem.

Other than that, though, I'm not aware of any other time its use would be justified. But still, lots of commands get mis-used... Probably shell.run() gets it the worst as far as ComputerCraft is concerned.

#65 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 16 July 2014 - 07:27 AM

View PostBomb Bloke, on 16 July 2014 - 07:22 AM, said:

But still, lots of commands get mis-used... Probably shell.run() gets it the worst as far as ComputerCraft is concerned.
shell.exit too :P oh and the entire Parallel API.

Edited by theoriginalbit, 16 July 2014 - 07:27 AM.


#66 CCNerd a.k.a CCNoob

  • Banned
  • 14 posts

Posted 16 July 2014 - 07:49 AM

paraell APi... anything to do multitask as an alternative? (like: guys who make OSes, how do you make them miltitask? like having a million buttons and a trillion textfields and they still handle well

goto("hell")

::hell::
print("yay")

#67 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 16 July 2014 - 08:38 AM

Generally, if you want a section of code to handle multiple goings-on, you just throw in a loop with an event listener and a whole bunch of "if" statements to see what events are being thrown. If a timer expires, you might flash a cursor... if a key is typed, you might add the resulting character to the text field you've got set as active... if a mouse button is clicked, you might set a different text field as active... and then you just repeat your loop, and wait for the next event.

A problem arises if you want to call functions that pull events on their own, such as read() (as this has the potential to mess up your event listener loop). You've then got two choices: Either re-write those functions so that they can be integrated directly into your listener loop's set of "if" statements, or run the code that calls those functions in a separate co-routine to your listener loop. The best solution varies depending on the complexity of the functions in concern... For example, it's trivial to re-write sleep() or rednet.receive(), but functions like read() or the song playing function from the "note" song playing API are often better ran via the likes of the parallel API.

Edited by Bomb Bloke, 16 July 2014 - 08:43 AM.


#68 Alice

  • Members
  • 429 posts
  • LocationBehind you.

Posted 02 August 2014 - 05:28 AM

This has probably been requested multiple times. Maybe even msyelf and I forgot, but here are to things I want:
Static typing
Method/Function overloading.
I like how Java enforces it and I want it to be implemented into Lua.

#69 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 03 August 2014 - 03:20 AM

Add a default way of doing 2d and 3d graphics Obvoisly ComputerCraft wouldn't ever get this capability even if Lua does(and I wouldn't have it any other way) but when I'm doing normal Lua it'd be nice to not have to use some engine.

#70 Alice

  • Members
  • 429 posts
  • LocationBehind you.

Posted 03 August 2014 - 04:07 AM

View PostGeforce Fan, on 03 August 2014 - 03:20 AM, said:

Add a default way of doing 2d and 3d graphics Obvoisly ComputerCraft wouldn't ever get this capability even if Lua does(and I wouldn't have it any other way) but when I'm doing normal Lua it'd be nice to not have to use some engine.
Good luck with that. As many people have told me in other areas, Lua's a scripting language. It's not likely they'll add custom support. As much as I hate it, Lua's supposed to be a lightweight language with minimal functions and syntax. They won't be adding that in any time soon.

#71 zekesonxx

  • Signature Abuser
  • 263 posts
  • LocationWhere you aren't

Posted 25 August 2014 - 06:24 PM

(this post was written without reading many of the other posts)
  • var++, var--, ++var, --var
  • Brackets instead of then/end
  • String concatenation done with `+` instead of `..`
  • Absolute comparisons `5 === "5"` = false
  • Arrays/objects with : instead of =
  • Comments done with // and /* */
  • Errors if you don't use local/global when declaring a variable


#72 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 25 August 2014 - 06:40 PM

Um , `5 == "5"` is already false.

#73 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 25 August 2014 - 07:12 PM

Oh I wish LuaJ had this, @zekesonxx Are you a fellow C# user? :D
local var = 10;
var += 1;
var++;
var--;
var *= 10;
var /= 2;
var ^= 3;
I'm not sure what else I would want to change, this is the only thing that comes to mind. I guess this topic is about Lua in general and if I'm not mistaken this has already been added in a new Lua version

#74 Ferdi265

  • Members
  • 21 posts

Posted 25 August 2014 - 07:45 PM

View PostBomb Bloke, on 16 July 2014 - 08:38 AM, said:

Generally, if you want a section of code to handle multiple goings-on, you just throw in a loop with an event listener and a whole bunch of "if" statements to see what events are being thrown. If a timer expires, you might flash a cursor... if a key is typed, you might add the resulting character to the text field you've got set as active... if a mouse button is clicked, you might set a different text field as active... and then you just repeat your loop, and wait for the next event.

A problem arises if you want to call functions that pull events on their own, such as read() (as this has the potential to mess up your event listener loop). You've then got two choices: Either re-write those functions so that they can be integrated directly into your listener loop's set of "if" statements, or run the code that calls those functions in a separate co-routine to your listener loop. The best solution varies depending on the complexity of the functions in concern... For example, it's trivial to re-write sleep() or rednet.receive(), but functions like read() or the song playing function from the "note" song playing API are often better ran via the likes of the parallel API.

I wrote an event loop API that gives you listener functions and handles os.pullEvent from 3rd party code by overriding os.pullEvent and also forwarding it to the loop API. using coroutines and adding functions to interact with the coroutine loop. My API

event functions like read() work when called from within my loop, but it halts everything during read. (A custom read could fix this) However, all events that fired during read are still handled, which is nice :D

Code executes during read. Read is a little messed up if you print during read, but it works :D

Edited by Ferdi265, 27 August 2014 - 04:28 PM.


#75 sci4me

  • Members
  • 225 posts
  • LocationEarth

Posted 25 August 2014 - 11:10 PM

View PostChallengeMe, on 03 December 2013 - 06:53 AM, said:

A lot of mine have already been mentioned, but I figure that I may as well state them.
  • Indentation requirements. More for my sake when debugging other people's code than anything else. I'm not a fan of the requirement when I'm actually writing a program myself due to the fact that sometimes I just want to test something quickly and not bother with indentation. But when I see some 600 line conglomeration without indentation I quickly exit the tab and return to browsing.
  • += and the like. The reasoning for this should be obvious.
  • Use curly braces for blocks - I'm not a fan of keywords for that purpose
  • Semi-colons to end statements. Simply for clarity's sake.
  • Function overloading. One of the reasons that I'm really liking Java.
  • Comments that begin with // not --. -- Looks ugly to me.
  • Compact the language somewhat: Do away with things such as "and" and replace them with symbols. I've always been a fan of compacting.
  • Declare things by default with a local scope, and specify global with global keyword or global symbol.

If the indentation requirement is 2 or 4 spaces, i'm fine with it. Although, in any other case I dislike that... maybe make it optional? IDK.
+=, etc. obvious reasons
real ternary operator, obvious reasons
Honestly, I dislike the semicolon thing. I mean, you CAN add semicolons can't you? I see them as extra typing...
I also prefer curly braces, don't like then and end...
Function overloading FTW! Although, it can be done... but its kind of a pain afaik... iirc SEE makes it a bit easier.
I don't really mind -- but I prefer //
Yeah, I prefer symbols like &/| instead of and and or...
I also agree on the local scope thing. Makes much more sense.

I also dislike the concat operator.. I mean, sure it is good to seperate it from math operators... but.. maybe a different symbol? I suppose its no big deal...
I do love that lua is dynamic but I also love static typing. This issue has me partially torn... but I don't think I really NEED static typing...
I LOVE lua's functional style, but better language support for OO would be nice...
Also, language level support for the bit api!!!

Better metamethods and operator overloading might be nice.. but its not that bad as is.

Oh, of course! Functions with different parameters but the same name!!! Seriously, WHY IS THIS NOT A THING? I know it can sorta be done with normal lua functions, but ... It could be so much better!

Don't get me wrong, I absolutely LOVE lua! It is my second favorite language besides Java. I think my biggest thing with it is the syntax... use curly braces and symbols for and and or. And real ternary.

#76 InputUsername

  • Members
  • 231 posts
  • LocationThe Netherlands

Posted 27 August 2014 - 02:26 PM

The one thing I would love to have (probably mentioned before) are metatables for other datatypes than tables (numbers, functions). And obviously things (++, --, && etc) mentioned before.

#77 Ferdi265

  • Members
  • 21 posts

Posted 27 August 2014 - 04:41 PM

sci4me said:

better language support for OO would be nice...
Lua uses an OO system that is different from the Classical System, the Prototypal System (which is also used in JavaScript)
In Lua you can easily implement inheritance via the __index metamethod, and constructor functions are also really easy to create.

Small Prototypal OO Library
Spoiler

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
overloadedFunction(unpack(someTable))

Edited by Ferdi265, 27 August 2014 - 04:44 PM.


#78 0099

  • Members
  • 52 posts

Posted 28 August 2014 - 01:07 PM

View Posttheoriginalbit, on 08 April 2014 - 01:32 AM, said:

View PostGraypup, on 07 April 2014 - 05:33 PM, said:

Who needs functional overloading? It can be done with some type() and some if statements.
I can become very verbose and annoying if there are too many arguments. Function overloading can make it a lot easier and cleaner. Take the following example:
--snip--

now go ahead and make something with the same functionality as above with if statements; it should be just as readable and contain no bugs/typos. k. go.

Speaking of annoyance, writing (and reading) 65536 different functions instead of 16 nested ifs doesn't seem very interesting... (Just an example, to make it obvious)
In addition, if statements are more flexible: sharing code chunks, checking arguments in different order (or in 2 orders at the same time), etc.

Everything that I "would change", actually can be changed from inside, that's the beauty of Lua. Currently I'm rewriting LÖVE framework (love2d.org) from inside, trying to completely remove callback mechanics from it, just because I don't like callbacks. Advice for theoriginalbit and all the others who want overloading: you can automate the process of "pseudo-overloading" by writing a function that checks argument types (call it "atype", for example) and using it like this:

function f(...)
   local args = {...}
   if atype(args, "string s1, number n, string s2") then
	  -- one function
   elseif atype(args, "string s1, string s2, thread cor, number m") then
	  -- another function
   else
	  error("Incorrect arguments to f")
   end
end

Also, see that variable names inside the strings? So, when atype at last finds correct argument types, before returning true, it rearranges the "args" table, so all your arguments are availble as args.s1, args.n etc.

If you want the syntax of overloading, well, that's a little harder, but also possible! Hint:
newfunc("boolean f(string s1, number n, string s2)", function(arg)
-- your code
end)
If you think that's ugly, well, there is one last way: write an additional program with bunch of "string.gsub"s that translate java-like definitions into that.

Edited by 0099, 28 August 2014 - 01:33 PM.


#79 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 28 August 2014 - 08:55 PM

I think people are forgetting the purpose of this thread:

theoriginalbit said:

...and I know that some of it is already implementable but the point of me writing this is to see what people WOULD change given the chance, even if it can already be done now.

Edited by MKlegoman357, 28 August 2014 - 08:55 PM.


#80 KaoS

    Diabolical Coder

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

Posted 21 September 2014 - 07:47 AM

View Posttheoriginalbit, on 02 December 2013 - 10:05 PM, said:

i know that it is not possible for Lua to have the functionality because it is not a statically typed language, however that being said this topic doesn't need to make sense in the realm of what it possible, it was more just me seeing what other people thought, even if it were not possible without changing everything about Lua. I find it very interesting to find out peoples ideas, perceptions, and opinions of programming, no matter how feasible it is.

I'm returning from a leave of absence so this may be late but you CAN actually implement all of the suggestions in your original post with a simple Lua code that changes the loadstring and similar functions. the binary number is the easiest example

local loads=loadstring

local convertToDecimal(nBinary)
  return tonumber(nBinary,2)
end

loadstring=function(sCode,...)
  if type(sCode)=="string" then
	sCode=sCode:gsub("b([01]+)",convertToDecimal)
  end
  return loads(sCode,...)
end
I realize you still have to ensure that that b[01]+ is not enclosed by quotation marks but you get the idea. I make a simple Lua file with similar workarounds that I use often and just include it in all my projects when I'm coding them, later I copy across the code I need or convert it to traditional syntax

EDIT: Lol I just read more of the thread, looks like I've fallen into the same trap as many others. At least I'm suggesting a code that changes the way Lua works rather than forcing you to code how Lua works but I apologise for not keeping to topic. I too would like Lua to support more metatable events. That's pretty much my only gripe other than perhaps a better Regex version and the RETARDED multiline comment thing

Edited by KaoS, 21 September 2014 - 08:03 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users