Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file: -- http://angg.twu.net/LUA/arithfbs.lua.html -- http://angg.twu.net/LUA/arithfbs.lua -- (find-angg "LUA/arithfbs.lua") -- Author: Eduardo Ochs <eduardoochs@gmail.com> -- Original: http://lua-users.org/lists/lua-l/2017-02/msg00139.html MT={} V={} N=0 function var(name) local t={name=name} V[name]=t _G[name]=t return setmetatable(t,MT) end function S(a) if type(a)=="table" then return a.name else return a or 0 end end function arithfb(a,b,op) local i=op .. "(" .. S(a) .. "," .. S(b) .. ")" if V[i]==nil then N=N+1; V[i]=var("t"..N,N); print(V[i].name ..'='..i) end return V[i] end t={"add", "sub", "mul", "div", "unm", "pow"} for i,v in next,t do MT["__"..v]=function (a,b) return arithfb(a,b,v) end end function vars(s) for x in string.gmatch(s,"(%w+)") do var(x) end end vars"x,y" return 2/3*x +(x^2-y^2)/(3*(x^2+y^2)), 2/3*y-2*(x*y)/(3*(x^2+y^2)) --[[ * (eepitch-lua51) * (eepitch-kill) * (eepitch-lua51) dofile "arithfbs.lua" --]]