Skip to content

jbp4444/EvalExpression

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EvalExpression

Lua/Corona code to evaluate mathematical expressions

(should not rely on anything specific to the Corona SDK, but I haven't double-checked)


This module can be used to parse simple math strings to produce numeric results:

  local text = "1 2*3"
  local result = evalString( text, nil )
  print( "result = "..result )
  -- should print 7

The particular use-case is in mobile apps where app-store regulations prohibit Lua's native "eval" function (since it could be used to execute arbitrary/bad code). This library does simple string manipulations and string-to-number conversions (which are allowed).

  • You can pass it a table of substitutions (key-value pairs) and those variables will be inserted before evaluating the math

  • It understands a half-dozen or so mathematical functions, but should be easily extendible if you need others (look for the "fcn_table" table)

About

Lua/Corona code to evaluate mathematical expressions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages