generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: why is ++ operator not in R Lua

Previous Thread :: Next Thread 
redlo43 is not online. 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
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
27 Feb 2014 08:52 PM
++ isn't even a real operator.
+= is, however.
Report Abuse
redlo43 is not online. 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 is not online. 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
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
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
MarkMcBlox is not online. MarkMcBlox
Joined: 04 May 2013
Total Posts: 873
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 is not online. 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 is not online. 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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
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 is not online. 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 is not online. 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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
28 Feb 2014 02:59 PM
Is += a unary operator?
Report Abuse
Dr01d3k4 is not online. 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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
28 Feb 2014 03:21 PM
So a++ is the only unary operator?

So whats the -{} unary operator thing?
Report Abuse
Dr01d3k4 is not online. 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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
28 Feb 2014 03:25 PM
There is a metamethod for unary negation, isnt there?
Report Abuse
Dr01d3k4 is not online. 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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
28 Feb 2014 03:28 PM
So how do I unary negate a table?
Report Abuse
Dr01d3k4 is not online. 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 is not online. 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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
28 Feb 2014 03:36 PM
dr01d: But how do I actually unary negate the table!
Report Abuse
Dr01d3k4 is not online. 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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
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 is not online. 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
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image