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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:52:34+00:00 2026-06-07T06:52:34+00:00

Say i have two files: One is called mainFile.lua: function altDoFile(name) dofile(debug.getinfo(1).source:sub(debug.getinfo(1).source:find(.*\\)):sub(2)..name) end altDoFile(libs/caller.lua)

  • 0

Say i have two files:

One is called mainFile.lua:

function altDoFile(name)
    dofile(debug.getinfo(1).source:sub(debug.getinfo(1).source:find(".*\\")):sub(2)..name)
end

altDoFile("libs/caller.lua")

function callBack()
    print "called back"
end

doCallback()

The other called caller.lua, located in a libs folder:

function doCallback()
    print "performing call back"
    _G["callBack"]()
end

The output of running the first file is then:

"performing call back"

Then nothing more, i’m missing a line!

Why is callBack never getting executed? is this intended behavior, and how do i get around it?

The fact that the function is getting called from string is important, so that can’t be changed.

UPDATE:
I have tested it further, and the _G[“callBack”] does resolve to a function (type()) but it still does not get called

  • 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-07T06:52:37+00:00Added an answer on June 7, 2026 at 6:52 am

    Why not just use dofile?

    It seems that the purpose of altDoFile is to replace the running script’s filename with the script you want to call thereby creating an absolute path. In this case the path for caller.lua is a relative path so you shouldn’t need to change anything for Lua to load the file.

    Refactoring your code to this:

    dofile("libs/caller.lua")
    
    function callBack()
        print "called back"
    end
    
    doCallback()
    

    Seems to give the result you are looking for:

    $ lua mainFile.lua 
    performing call back
    called back
    

    Just as a side note, altDoFile throws an error if the path does not contain a \ character. Windows uses the backslash for path names, but other operating systems like Linux and MacOS do not.

    In my case running your script on Linux throws an error because string.find returns nill instead of an index.

    lua: mainFile.lua:2: bad argument #1 to 'sub' (number expected, got nil)
    

    If you need to know the working path of the main script, why not pass it as a command line argument:

    C:\LuaFiles> lua mainFile.lua C:/LuaFiles
    

    Then in Lua:

    local working_path = arg[1] or '.'
    dofile(working_path..'/libs/caller.lua')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two files where there is one number per line File 1
Lets say i have at least two lua script files. test1.lua test2.lua both define
Say I have two .cpp files and in one of them I wrote extern
Let's say I have two files, each one has a class. How can I
Let's say I have two files default.aspx and the associated default.aspx.cs . default.aspx.cs: protected
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
Say I have file.php with three functions and an echo statement: function one() {
I have two files. First one has 482 lines. Second one has only 519
A bit context. Let's say I have source files, which need to end up
Say I have two web servers, one local development and one live. Under SVN

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.