Page 1 of 1

Attempt to call a number... [Solved]

Posted: Thu Aug 26, 2010 6:10 pm
by Person
So, I was chugging along, coding my project. I have a bad habit of coding huge amounts and then deciding to check to see if it works. So I wrote 2 huge functions and a little one all without checking to see if they work and what do you know, I can't get the biggest one to work for the life of me. It keeps telling me that I'm attempting to call a number on line 43, which means (according to my internet searching) that lua expected a function and got a number instead. So what's the deal? The entire line looks like this:

Code: Select all

ua_num	= ((l_x2 - l_x1)(a_y1 - l_y1)) - ((l_y2 - l_y1)(a_x1 - l_x1))	-- The  numerator and denomenator are calculated seperately
So I don't see any problem, all the variables in question were set before the call, so I'm very confused...
I uploaded the whole code for your guys to check if you feel like it. Please halp? :brows:

Re: Attempt to call a number...

Posted: Thu Aug 26, 2010 6:25 pm
by knorke
missing multiplication signs?
ua_num = ((l_x2 - l_x1) * (a_y1 - l_y1)) - ((l_y2 - l_y1) * (a_x1 - l_x1))

Re: Attempt to call a number...

Posted: Thu Aug 26, 2010 6:38 pm
by Person
:shock:
your kidding?
*revises code*
*facedesk* I feel very stupid right now... I thought that the brackets implied multiplication, my bad!

Re: Attempt to call a number... [Solved]

Posted: Thu Aug 26, 2010 7:06 pm
by Luiji
Sadly the mathematical idea that the brackets imply multiplication is rarely implemented by programming languages. Interestingly, Lua, unlike most programming languages, is resolved the syntax as a function call as supposed to raising syntax errors.

Re: Attempt to call a number... [Solved]

Posted: Thu Aug 26, 2010 7:15 pm
by thelinx
I bet you could do some metatable magic to make it multiply stuff in cases like this.

Re: Attempt to call a number... [Solved]

Posted: Thu Aug 26, 2010 7:17 pm
by Luiji
Mmm...metatables...

Re: Attempt to call a number... [Solved]

Posted: Thu Aug 26, 2010 7:19 pm
by thelinx
A quick visit to #lua later...
21:17 < krka> debug.setmetatable(0, {__call = function(x, y) return x * y end})
21:17 < krka> return (5)(6+7)
21:17 < krka> --> 65
21:18 < thelinx> heh, awesome
21:18 < krka> return 5(6+7) is a syntax error however