redlo43
|
  |
| Joined: 16 Feb 2011 |
| Total Posts: 4722 |
|
|
| 27 Feb 2014 08:52 PM |
it's so annoying to type foo = foo + 1
|
|
|
| Report Abuse |
|
|
|
| 27 Feb 2014 08:52 PM |
++ isn't even a real operator. += is, however. |
|
|
| Report Abuse |
|
|
redlo43
|
  |
| Joined: 16 Feb 2011 |
| Total Posts: 4722 |
|
|
| 27 Feb 2014 08:54 PM |
| my friend told me it was a unary operator |
|
|
| Report Abuse |
|
|
200AB
|
  |
| Joined: 24 Aug 2010 |
| Total Posts: 1604 |
|
|
| 27 Feb 2014 08:57 PM |
++ is a real operator. int lol = 1; lol++; >lol=2 |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2014 09:04 PM |
I know you can do var++ in most languages, but I thought you were saying you could do var ++ 1. I was going to like die if that's what you meant, but never mind. |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2014 10:54 PM |
I have no idea why it isn't.
I'd love to do
var += 4 or var -= 4.
I've done it with Java and such.
~ King of the Bluesteel ~ |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 27 Feb 2014 11:36 PM |
From the Lua FAQ:
Why does Lua lack the += operator, etc.?
One of Lua's design goals is simplicity. Most languages are large, meaning that they have many sophisticated features built-in. Examples are C, C++, Python, Lisp, ML. A very few languages are small. Examples are Forth and Lua. Lua aims to provide a small range of atomic features which are truly essential, and from which many other sophisticated features can be constructed if desired. Examples of sophisticated features which can be added to Lua from within the language include modules, object orientation, and now exceptions and threads which can be implemented via coroutines in Lua 5. The absent += operator is one more example. |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 27 Feb 2014 11:42 PM |
| Also, if you want this sort of thing, you might try MoonScript. It's a language which compiles down to Lua. |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2014 11:04 AM |
"One of Lua's design goals is simplicity."
But how is +=, -=, *=, /=, ^= not simple?
Also, I take it imaginary numbers too complex for them. |
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 28 Feb 2014 02:47 PM |
"my friend told me it was a unary operator"
Your friend is wrong. A unary example would be 11111111111111111111111111(25). |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 28 Feb 2014 02:57 PM |
| @Morash: No ++ is a unary operator because it has one (un) operand, whereas + is a binary operator because it has 2 operands and ?: is a ternary operator because it has 3 operands. |
|
|
| Report Abuse |
|
|
| |
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 28 Feb 2014 03:04 PM |
| No because it's "a += b" - 2 operands; if it were a function it'd have 2 parameters. |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2014 03:21 PM |
So a++ is the only unary operator?
So whats the -{} unary operator thing? |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 28 Feb 2014 03:24 PM |
-{} What?
And ++ isn't the only, there's also -- and - for negative number, but is binary for subtraction (-a vs a - b) |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2014 03:25 PM |
| There is a metamethod for unary negation, isnt there? |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 28 Feb 2014 03:27 PM |
http://wiki.roblox.com/index.php?title=Metatable Yes, __unm |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2014 03:28 PM |
| So how do I unary negate a table? |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 28 Feb 2014 03:30 PM |
do u even metatable?
local tbl = {1, 2, 3}; setmetatable(tbl, { __unm = function (self) for i = 1, #self, 1 do rawset(self, i, -rawget(self, i)); end; });
|
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 28 Feb 2014 03:33 PM |
the - operator is binary.
If you're using -10, behind the scenes that gets turned into 0-10 |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2014 03:36 PM |
| dr01d: But how do I actually unary negate the table! |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 28 Feb 2014 03:36 PM |
"Lua supports the usual arithmetic operators: the binary + (addition), - (subtraction), * (multiplication), / (division), % (modulo), and ^ (exponentiation); and unary - (negation)" From the 5.1 reference manual. |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2014 03:38 PM |
Example code!
You are saying you can do it, but I am wondering how?
Do I just say
"-table"? |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 28 Feb 2014 03:39 PM |
| Yes... that's how metatables and unary negation work. |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2014 03:40 PM |
local tbl = {1, 2, 3}; setmetatable(tbl, { __unm = function (self) for i = 1, #self, 1 do rawset(self, i, -rawget(self, i)); end; end; --You forgot that! >:o });
-tbl
>An Error. |
|
|
| Report Abuse |
|
|