Unary Operators

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
sudo_radish
Prole
Posts: 3
Joined: Wed Nov 02, 2016 4:42 pm

Unary Operators

Post by sudo_radish »

Is there a list of Unary operators that is used in Love?
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Unary Operators

Post by s-ol »

You are looking for Lua's unary operators, not LÖVEs, since LÖVE isn't a language.

The lua reference lists the minus, length operator (#) and "not":
https://www.lua.org/manual/5.1/manual.html#2.5

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
sudo_radish
Prole
Posts: 3
Joined: Wed Nov 02, 2016 4:42 pm

Re: Unary Operators

Post by sudo_radish »

Thanks for the feedback.

I did check the Lua docs first but I didn't know if Love had some modified stuff in it like Pico 8 does.

it is mainly because I am a touch lazy and I like the way I can do

Code: Select all

a+=1
or

Code: Select all

a-=1
over

Code: Select all

a = a+1
. :death:

Stupidly I tried it first and got a great big fat error on compile lol. And I didn't want to think I missed something obvious. :neko:
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Unary Operators

Post by s-ol »

sudo_radish wrote:Thanks for the feedback.

I did check the Lua docs first but I didn't know if Love had some modified stuff in it like Pico 8 does.

it is mainly because I am a touch lazy and I like the way I can do

Code: Select all

a+=1
or

Code: Select all

a-=1
over

Code: Select all

a = a+1
. :death:

Stupidly I tried it first and got a great big fat error on compile lol. And I didn't want to think I missed something obvious. :neko:
+= and -= aren't unary operators though, they are a special case of assignment operators (and Lua as used in Löve only has the assignment operator '=' (singular).

Assignment operators look like infix operators but they actually aren't since

a) they don't form an expression / yield a value (can't do print(a = 3) is illegal)
b) the left hand side can't be any expression, it must be a variable (can't do 3 = 3)

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest