Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
lua-until EOL dstack = {} rstack = {program} dpush = function( val ) tinsert(dstack, 1, val) end dpop = function( ) return tremove(dstack, 1) end rpush = function( prog ) tinsert(rstack, 1, prog); program = prog end rpop = function( ) tremove(rstack, 1); program = rstack[1] end dict[""] = function( ) getline() if program.pos == strlen(program.string) then rpop() end end mf = function( code ) rpush({string=code, pos=0}) end re(res, ";;", "[ \t\n];;([ \t\n]|$)") dict["::"] = function( ) local word, code = getword(), getuntilre(";;") dict[word] = function( ) mf(%code) end end dict["::lua"] = function() local word, code = getword(), getuntilre(";;") dict[word] = dostring(format("return function() %s\nend", code)) end EOL ::lua * dpush(dpop()*dpop()) ;; ::lua dup dpush(dstack[1]) ;; ::lua . pa(dpop()) ;; ::lua val dpush(eval(getword())) ;; :: square dup * ;; :: cube dup square * ;; val 5 cube . val exit() #* cd ~/miniforth/ mylua -f miniforth1.lua cube1.mflua #*