简体   繁体   中英

Loading files from external directories with embedded lua in C++ ?

I'm writing a basic scripting system using lua in C++. One of my glue functions is called from this:

lua_register(luaVM, "openFile", l_dial.l_specifyF);

And is coded as follows:

static int l_specifyF(lua_State* luaVM) {
    const char* c = lua_tostring(luaVM, -1);
    cDialogManager::getSingletonPtr()->clearVector();
    try{
        luaL_dofile(luaVM, c);
    } 

    catch(...) {
        cout << "Unable to open file" << endl;
        luaL_dofile(luaVM, "startup.lua");
    }
    return 1;
}

When I call it in my application, it works 100% if I call a file from a local directory like openFile("somefile.lua") or openFile("someotherfile.lua") , but crashes when calling files located in external folders such as openFile("scripts/ohdear.lua") .

Note that this does actually work on some occasions, which only adds to the confusion. Are there any reasons for this? How can I remedy my application to use files from external directories?

From your description I seriously doubt that it has something to do with folder struction. My guess is, that you are observing an late reaction from an earlier error...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM