Lua Rocks
Sun 14 September 2014
Inspired by reading Lua - an extensible extension language, specifically the section on using fallbacks to implement an expression parser, I wanted to see if I could do so in a safe manner. With safe meaning parsed expressions must not be able to execute arbitrary code.
Half an hour later, I have to say it is surprisingly easy! Less than 50 lines (including comments) is all it takes:
function parse(expression) local op, create -- Calculate each subexpression at most once, otherwise just return the cached -- result. Note that this <span class="more">...</span>