Jump to content




[Solved] Table math


  • You cannot reply to this topic
2 replies to this topic

#1 pofferman

  • Members
  • 37 posts

Posted 29 August 2015 - 05:28 PM

Hey guys, so i wonder if you could do math with a table like this

local temp = {
"(",
"10",
"+",
"5",
")",
"*",
"2"
}
print(table.concat(temp))

The code above outputs "(10+5)*2"
But i wonder if somehow i could make it do the math, so it outputs "30"?

Attached Thumbnails

  • Attached Image: Udklip.PNG

Edited by pofferman, 05 September 2015 - 10:12 PM.


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 29 August 2015 - 05:42 PM

Change the last line to this:

print( loadstring( "return " .. table.concat( temp ) )() )

To clarify, loadstring turns a string into a function. I added "return " to the beginning of the operation so that the created function would return the result. I then called the function, which returned the result, and the result was printed by print.

#3 pofferman

  • Members
  • 37 posts

Posted 29 August 2015 - 06:02 PM

I thank u so mutch:D
that really worked :) ty ty ty :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users