A lua wrapper for exprtk (C++ Mathematical Expression Parsing And Evaluation Library)
local exprtk = require('lua-exprtk')
local varMap = exprtk.variable_map.new()
varMap:insert('a')
local symbols = exprtk.symbol_table.new()
symbols:add_constants()
symbols:add_variables(varMap)
local expr = exprtk.expression.new()
expr:register_symbol_table(symbols)
local parser = exprtk.parser.new()
local success,err = parser:compile('clamp(-0.5,sin(a*pi/180),0.5)', expr)
if not success then
print('Error during parsing:', err)
return
end
for i=0,360 do
varMap:set('a', i)
print(i, expr:value())
endFor a full list of expressions, look here.
- lua-exprtk was compiled and tested with macOS 10.14, Windows 10 x64 and Ubuntu 20.04 x64.
- Compilation takes some time, most probably because of the huge header-only libs sol2 and exprtk.
- lua-exprtk is also available via LuaRocks.