Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:33:44+00:00 2026-06-09T15:33:44+00:00

I have a post-hook function that receives some data for itself, reference to another

  • 0

I have a post-hook function that receives some data for itself, reference to another function and arguments for that arbitrary function in .... This function does some post-processing, after referenced function returns. For simplicity let’s just note time:

function passthrough(tag, func, ...)
    metric1[tag] = os.time()
    func(...)
    metric2[tag] = os.time()
end

Since I need to postprocess, I can’t immediately return func(...) and I don’t know in advance how many returns there will be. How can I passthrough those returns after I’m done with post-processing?

So far I can think only of packing call in local results = { func(...) } and then using return unpack(results) or making a postprocessor factory that’d generate postprocessing closure with all necessary data as upvalues:

local function generate_postprocessor(tag)
    return function(...)
        metric2[tag] = os.time()
        return ...
    end
end

function passthrough2(tag, func, ...)
    metric1[tag] = os.time()
    return generate_postprocessor(tag)(func(...))
end

However, both those approaches would introduce some overhead that is undesirable, considering high amount of iterations and real-time nature of application. Is there anything simpler?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:33:45+00:00Added an answer on June 9, 2026 at 3:33 pm

    You don’t need the closure. func is called before calling your closure generator anyway. You just need a function that passes its arguments straight through to its return values to give you a hook point for your second tag:

    function passthrough_return(tag, ...)
        metric2[tag] = os.time()
        return ...
    end
    
    function passthrough(tag, func, ...)
        metric1[tag] = os.time()
        return passthrough_return(tag, func(...))
    end
    

    You’re still getting the overhead of an extra function call, but that’s better than creating a closure or a table and far less than the overhead of your pre/post processing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a post-commit hook that does stuff in ruby. It works very well
I have a post-commit hook in svn that runs fine from the command line
I have a post-build event that runs some commands for a c# project. The
I have a post-update hook on my server, such that when I git push
My post commit hook is not running after git. I have verified that the
I have a git post receive hook that will trigger a build on my
Is there a Chrome extension post install hook/API function that will let me perform
I have a post commit hook that will save the svn log as an
I found a post-receive hook for Git after some googling that I use to
i have this problem to find a particular xml node l have post this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.