Jump to content

Forcar um calculo apartir de uma string


Recommended Posts

Posted (edited)
Existe alguma funcao para forcar um calculo neste estilo ?
local teste = "123+44/22-33"
iprint(tonumber(teste))
Edited by Diogo FIh
  • Moderators
Posted

Moving this into the Portuguese scripting section.

  • Like 1

Give a man a fish and you feed him for a day. Teach him how to fish and you feed him for a lifetime - Lao Tzu

Posted
On 06/03/2022 at 11:54, Diogo FIh said:
Existe alguma funcao para forcar um calculo neste estilo ?
local teste = "123+44/22-33"
iprint(tonumber(teste))

Você pode utilizar o loadstring de Lua para isso. Veja o seguinte exemplo:

local teste = "123+44/22-33"
local final = loadstring('return '..teste)()
print(final) --output: 92

 


Dê um THANKS se minha ajuda ou comentário foi útil para você.   spacer.png 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...