Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
Which of the 2 implementations more than acceptable? - Q&A

Which of the 2 implementations more than acceptable?

0 like 0 dislike
Often there are situations when it is possible to equate an object to a function, and this f-tion will be called when certain conditions and parameters, but often this is not enough - I want some f-functions to hang for 1 object. For this purpose I have written 2 implementation. Actually I want to know which method is more acceptable, I did a test on multiple execution of the 4 functions (2^20 times) - by the time the result is approximately equal.
The first way (in depth)

F-tsii are recorded in tables, and tables one to another, each table in metatable stated that the call thereof, executed f-tion and the nested table, and so the chain:
local noop = function() end local storage = {noop} setmetatable(storage, {__call = function(slf, ...) return slf[1](...) end}) local b = storage function add(f) add f-tion in the line of execution local texe = {noop, f} setmetatable(texe, {__call = function(self, ...) self[2](...); return self[1](...) end}) b[1] = texe b = texe end function find(f_obj) - search f-tsii from line if found returns its parent table (itself found f-tsiya item 2 in the table) local stack, prevStack = storage, storage while (type(stack) == "table") do stack = stack[1] if stack[2] == f_obj then return prevStack end prevStack = stack end end -- not cumbersome search f-tsii in the line function del(fun) -- removal of the piano from the line local a = find(fun) a[1] = a[1][1] end

asked by | 7 views

Please log in or register to answer this question.

Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers


12.7k users

24,788 questions
46,220 answers
12,715 users