plus one

In javascript, variable ++ adds one to aformentioned variable. What is the lua equivelant of this?

Thanks!
[import]uid: 99031 topic_id: 30157 reply_id: 330157[/import]

I don’t think Lua has this, maybe I’m wrong… Would be awesome if it did! =D [import]uid: 144504 topic_id: 30157 reply_id: 120725[/import]

well actually I’m pretty sure I saw it somewhere around the tutorials on this site, but I can’t find it again. Damn! [import]uid: 99031 topic_id: 30157 reply_id: 120734[/import]

Nope, Lua does not support the “C” style auto increment/decrement operators (found in JavaScript, Java, PHP, ActionScript and just about every other language based on C).

You are stuck doing:

i = i + 1

And there is a reason for that.

One of the things that makes programming hard is syntax and the more symbolic the language is, the harder it is for non-programmers and new programmers to grasp. Lets look at one of the worst offenders: Lisp:
(labels ((foo (x) (and (<= 0 x) (cons x (foo (1- x)))))) (format t (format nil " ~~{~~ &~~@(~~% ~~R ~A ~A!~~ ) ~~:*~~ &~~@(~~R ~0@*~A!~~)~~&~~@(~2@*~A!~~) ~~&~~ @(~~[~A~~:; ~~:*~~ R ~~:*~~] ~0@*~A!~~)~~}" "bottles of beer" "on the wall" "take one down, pass it around" "no more" ) (foo 99)))[/code]C and it's children is also a cryptic language, but oh so beautiful at the same time.[cpp]int i;const char *msg[] = {"bottles of beer", "on the wall", "take one down, pass it around", "no more"};for(i=99;i>0;i--) { printf("%d %s %s\n",i, msg[0], msg[1]); printf("%d %s\n",i,msg[0]); printf("%s\n",msg[2]);}printf("%s\n",msg[3])exit;[/cpp]All of those braces, parens, semi-colons and such are very difficult for new programmers to digest. Now look at Lua:[code]local msg = {"bottles of beer", "on the wall", "take one down, pass it around", "no more"}for i = 99, 1, -1 do print(i,msg[0],msg[1]) print(i,msg[[0]) print(msg[2])endprint(msg[3])[/code]The language is much cleaners and easier to read. i = i + 1 or i++;Which is easier to digest? [import]uid: 19626 topic_id: 30157 reply_id: 120740[/import]

OMG, @robmiracle, Lisp looks like a language from another planet.

Naomi [import]uid: 67217 topic_id: 30157 reply_id: 120750[/import]

Yea even with my experience I can’t wrap my head around Lisp. [import]uid: 19626 topic_id: 30157 reply_id: 120756[/import]

Ah but LUA has

local foo = bar>0 and foothis or foothat [import]uid: 160496 topic_id: 30157 reply_id: 120758[/import]

Honestly guys,

LUA is a PLEASURE!

And the worse language is Assembly IMHO!


PS: I`ve studied it about 4 years continuously for programming micro-controllers such as PIC, ATMEL, etc and even so I can tell you that I do not remember absolutely nothing! Just the truth. :S
Cheers,
Have Fun on the Moon Devs.
Rodrigo. [import]uid: 89165 topic_id: 30157 reply_id: 120806[/import]

I don’t think Lua has this, maybe I’m wrong… Would be awesome if it did! =D [import]uid: 144504 topic_id: 30157 reply_id: 120725[/import]

well actually I’m pretty sure I saw it somewhere around the tutorials on this site, but I can’t find it again. Damn! [import]uid: 99031 topic_id: 30157 reply_id: 120734[/import]

Nope, Lua does not support the “C” style auto increment/decrement operators (found in JavaScript, Java, PHP, ActionScript and just about every other language based on C).

You are stuck doing:

i = i + 1

And there is a reason for that.

One of the things that makes programming hard is syntax and the more symbolic the language is, the harder it is for non-programmers and new programmers to grasp. Lets look at one of the worst offenders: Lisp:
(labels ((foo (x) (and (<= 0 x) (cons x (foo (1- x)))))) (format t (format nil " ~~{~~ &~~@(~~% ~~R ~A ~A!~~ ) ~~:*~~ &~~@(~~R ~0@*~A!~~)~~&~~@(~2@*~A!~~) ~~&~~ @(~~[~A~~:; ~~:*~~ R ~~:*~~] ~0@*~A!~~)~~}" "bottles of beer" "on the wall" "take one down, pass it around" "no more" ) (foo 99)))[/code]C and it's children is also a cryptic language, but oh so beautiful at the same time.[cpp]int i;const char *msg[] = {"bottles of beer", "on the wall", "take one down, pass it around", "no more"};for(i=99;i>0;i--) { printf("%d %s %s\n",i, msg[0], msg[1]); printf("%d %s\n",i,msg[0]); printf("%s\n",msg[2]);}printf("%s\n",msg[3])exit;[/cpp]All of those braces, parens, semi-colons and such are very difficult for new programmers to digest. Now look at Lua:[code]local msg = {"bottles of beer", "on the wall", "take one down, pass it around", "no more"}for i = 99, 1, -1 do print(i,msg[0],msg[1]) print(i,msg[[0]) print(msg[2])endprint(msg[3])[/code]The language is much cleaners and easier to read. i = i + 1 or i++;Which is easier to digest? [import]uid: 19626 topic_id: 30157 reply_id: 120740[/import]

OMG, @robmiracle, Lisp looks like a language from another planet.

Naomi [import]uid: 67217 topic_id: 30157 reply_id: 120750[/import]

Yea even with my experience I can’t wrap my head around Lisp. [import]uid: 19626 topic_id: 30157 reply_id: 120756[/import]

Ah but LUA has

local foo = bar>0 and foothis or foothat [import]uid: 160496 topic_id: 30157 reply_id: 120758[/import]

Honestly guys,

LUA is a PLEASURE!

And the worse language is Assembly IMHO!


PS: I`ve studied it about 4 years continuously for programming micro-controllers such as PIC, ATMEL, etc and even so I can tell you that I do not remember absolutely nothing! Just the truth. :S
Cheers,
Have Fun on the Moon Devs.
Rodrigo. [import]uid: 89165 topic_id: 30157 reply_id: 120806[/import]