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 8209439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:43:17+00:00 2026-06-07T09:43:17+00:00

Running an almost trivial script in lua with dofile, 10000 times, takes about 52

  • 0

Running an almost trivial script in lua with dofile, 10000 times, takes about 52 seconds in this machine, but if i run 10000 times “lua52 script.lua”, it takes 3 or 4 times more. I’m aware that there’s more system calls involved and other overhead, but what i try to achieve is running scripts with a timeout of let’s say 3 seconds, and print out the output.
My problem is scripts with infinite loops, intentional or not, for example:

while(true) do
end

Can i make a timeout for a dofile from within Lua?
Is my only option to call the interpreter each time with timeout(3)?

  • 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-07T09:43:18+00:00Added an answer on June 7, 2026 at 9:43 am

    It feels a bit wrong for a novice like me to be correcting lhf on Lua matters, but here goes; passing “count” to debug.sethook is the same as passing “c” or “call”, the correct mask to pass to fire the associated function after n VM instructions is “”.

    As such, to restrict the runtime of code loaded from dofile(), use something like the following:

    local f = function() error("timeout") end
    local x,y = xpcall(function()
      debug.sethook(f, "", 1e8)
      local ret = dofile("script.lua")
      debug.sethook()
      return ret
    end, debug.traceback)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to get this code running. I am almost there but I got
I've almost got this figured out by using previous questions, but I'm running into
Running this program is printing forked! 7 times. Can someone explain how forked! is
Running this query takes a long time: SELECT host,ip FROM arecords WHERE ip IN
My site is almost up and running, but in the original code there are,
We'll do this on almost every hit to our site. Hosted at Heroku, running
I know this might be redundant but I have had the same query running
I'm almost certain I know the answer to this question, but I'm hoping there's
I know almost nothing about linq. I'm doing this: var apps = from app
This may sound trivial, but I'm pretty sure this question hasn't been asked, or

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.