Dia Report Share Posted November 29, 2010 do -- The marker table serves double duty. It is a private key in the -- hash, and also serves as the hashes metatable. local marker = {} -- If the key is not found, we use the saved function (stored with the -- private key) to generate a value, and save it. function marker.__index(t, k) local val = t[marker](k) t[k] = val return val end -- We make the table look like a function, just deferring to lookup function marker.__call(t, k) return t[k] end -- They'll hit an endless loop if they do Memoize(nil). So we do -- something reasonable. We could also report an error, of course. function Memoize(fn) local self = {[marker] = fn or function(x) return nil end} setmetatable(self, marker) return self endend -- test 2do -- The marker table serves double duty. It is a private key in the -- hash, and also serves as the hashes metatable. local marker = {} -- If the key is not found, we use the saved function (stored with the -- private key) to generate a value, and save it. function marker.__index(t, k) local val = t[marker](k) t[k] = val return val end -- We make the table look like a function, just deferring to lookup function marker.__call(t, k) return t[k] end -- They'll hit an endless loop if they do Memoize(nil). So we do -- something reasonable. We could also report an error, of course. function Memoize(fn) local self = {[marker] = fn or function(x) return nil end} setmetatable(self, marker) return self endend Link to comment Share on other sites More sharing options...
Filidh Report Share Posted November 29, 2010 Like that, Zeilen wären noch nicht schlecht (Zeilennummernrand). Example: --blablabla Das würde bedeuten das er sich links ab der Zeile 67 dann runterarbeitet. Link to comment Share on other sites More sharing options...
Dia Author Report Share Posted November 29, 2010 Like that, Zeilen wären noch nicht schlecht. Example: blabblub Das würde bedeuten das er sich links ab der Zeile 67 dann runterarbeitet. Muss ich mal schaun obs sowas gibt. Ging mir erstmal darum dass er LUA Code unterstützt und nicht als C Code behandelt :) Ja, linenumbers sollten drin sein, sind aber nicht. :) Danke Prettify Link to comment Share on other sites More sharing options...