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

  • Home
  • SEARCH
  • 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 6615425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:27:36+00:00 2026-05-25T20:27:36+00:00

Note that this question is about pure Lua. I do not have access to

  • 0

Note that this question is about pure Lua. I do not have access to any module or the C side. Additionally, I can not use the IO, the OS or the debug library.

What I’m trying to make is a function that receives, as parameters:

  • a number that is an ammount of second
  • a callable value

By ‘a callable value’, I mean a value that can be called. This can be:

  • a function
  • a table with a metatable that allows calling (through a __call metamethod)

Here’s an example of a callable table:

local t = {}
setmetatable(t, {
  __call = function() print("Hi.") end
})
print(type(t)) --> table
t() --> Hi.

Here’s the function:

function delay(seconds, func)
  -- The second parameter is called 'func', but it can be anything that is callable.
  coroutine.wrap(function()
    wait(seconds) -- This function is defined elsewhere. It waits the ammount of time, in seconds, that it is told to.
    func() -- Calls the function/table.
  end)()
end

But I have a problem. I want the function to throw an error if the parameter ‘func’ is not callable.

I can check if it is a function. But what if it is a table with a metatable that allows calling?
If the metatable of the table is not protected by a __metatable field, then, I can check the metatable to know if it is callable, but, otherwise, how would I do it?

Note that I have also thought about trying to call the ‘func’ parameter with pcall, to check if it is callable, but to do that, I need to call it prematurely.

Basically, here’s the problem: I need to know if a function/table is callable, but without trying to call it.

  • 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-05-25T20:27:36+00:00Added an answer on May 25, 2026 at 8:27 pm

    In general, if the metatable does not want you to be able to get it (by defining __metatable to being something special), then you’re not going to get it. Not from Lua.

    However, if you want to cheat, you can always use debug.getmetatable, which will return the metatable associated with that object.


    You don’t have to prematurely call anything with pcall. Observe:

    pcall(function(...) return PossibleFunction(...) end, <insert arguments here>)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(note that this question is not about CAS, it's about the May fail spuriously
Please note that this is asking a question about constructors, not about classes which
Please note that this question is not about the mysql query per se, but
Please note that this question is not about the mysql query per se, but
Note that this function does not have a { and } body. Just a
This question is about a general technique in SQL, that I can't quite work
Please note that this question is about CGLayer (which you typically use to draw
Please note that this question is from 2008 and now is of only historic
[Please note that this is a different question from the already answered How to
Please note that this is not homework and i did search before starting 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.