wiremod / wire

Garry's Mod add-on that allows users to wire up components in order to make more elaborate automatic and user-controlled contraptions.
http://www.wiremod.com
Apache License 2.0
554 stars 332 forks source link

E2 doesn't allow method-style functions on numbers #934

Closed airidas338 closed 9 years ago

airidas338 commented 9 years ago

Example: function void number:testFunction() { }

Enable numbers as function object types, so we could create functions similar to these n:teamDeaths(), teamName() which is implemented in E2. (No, i don't want to add number as parameter, this way it looks better, nearly can simulate object based scripting)

Divran commented 9 years ago

hm, try normal:test() ?

bigdogmat commented 9 years ago

Returns the same error

TomyLobo commented 9 years ago

It's pretty simple actually:

  1. What's the error?
  2. Are we throwing it?
  3. Is Garry throwing it?
  4. Is Lua throwing it?
  5. If 2., was there a reason for introducing that error?
  6. Is that a good reason?
  7. Does that reason still apply?
TomyLobo commented 9 years ago

Maybe E2 needs user-defined types, so he can have a Team type :)

Divran commented 9 years ago

Currently the easiest way to fake objects is to use tables and then create functions on the table type.

oldmud0 commented 9 years ago

Agreed, we should get some user-defined types.

But Divran is already directing people to things that are "better" than E2 so why bother.

Divran commented 9 years ago

@oldmud0 development for E2 has been pretty stale for years

EDIT: doesn't mean we don't randomly get the urge to do small stuff, or accept pull requests

bigdogmat commented 9 years ago

Any update on this issue?

EDIT: We're doing a check here https://github.com/wiremod/wire/blob/master/lua/entities/gmod_wire_expression2/base/parser.lua#L601-L622 to see if the type is normal and if so error out, I removed the line and the number as function object worked fine.

Is their any reason to have that check?

Divran commented 9 years ago

That's weird. I don't see any reason to have that.

bigdogmat commented 9 years ago

Neither did I, maybe caused an old bug? If it did I'd think it's been fixed by now as I wasn't able to produce any errors using numbers as objects.

TomyLobo commented 9 years ago

In this case, I'd say remove it and see if people complain :) You can try doing shenanigans with all the different kinds of number literals to see if they cause problems.

Divran commented 9 years ago

Apparently Syranide did this, just saying

bigdogmat commented 9 years ago

So should we just comment out the line just incase something happens? I mean unless someone can contact Syranide and ask why it was added( doubt he remembers ), we don't have much to go off of. And should I create a pull request for this or would it be easier for someone to commit it directly in?

syranide commented 9 years ago

The only thing that makes sense to me is that it was added to give a useful error message. My thinking probably being that it doesn't really make sense to have methods on numbers, they're "too primitive" in a sense and the only operations that really makes sense are already operators. Anything that operates on numbers are better provided as functions across the board (from a CS perspective).

Anyway, do as you please :) because I can't imagine it being there for any other reason, and it should be immediately obvious if it has to be there (like not parsing).

Divran commented 9 years ago

My thinking probably being that it doesn't really make sense to have methods on numbers, they're "too primitive" in a sense and the only operations that really makes sense are already operators

This is E2, we don't give a fuck

EDIT: as long as it's better than PHP, but we couldn't make E2 worse than PHP even if we tried.

TomyLobo commented 9 years ago

PHP has classes with polymorphism... let's at least add user-defined types. together with method-style they feel like non-polymorphic classes Shorthand would be automatically assigned from a pool of x00..x99, so we have 100 user-defined classes :)