Hello! I have been trying to embed lua into my application, and I have strange behavior that I could not understand. I'm sure that this is not normal.

First off, I have written a binding in order to interface my D code with Lua Code.
..:://\\::..
extern(C) nothrow int addSprite(lua_State *L){
    try{
        string path = to!string(lua_tostring(L,1));
        string name = to!string(lua_tostring(L,2));
        TextureManager.getInstance().addSprite(path,name);
    }catch(Exception e){
    }
    return 0;
}
..:://\\::..

Now here is my lua script.
..:://\\::..

Texture_addSpriteSheet("rsc/image/image.png","Hero");

..:://\\::..

Now here is how I execute said lua scripts:
..:://\\::..
            int s = luaL_loadfile(L,cast(char*)script_list[name]);
            if(!s)
                s = lua_pcall(L,0,LUA_MULTRET,0);
            if(s){
                write("Error : ");
                writeln(lua_tostring(L,-1));
                lua_pop(L,1);
            }
..:://\\::..

Now the strange thing here is, I have around 5 lines of code that adds other sprites aside from "image.png" but for some strange reason, the other 4 does its job, but this line doesn't. There are no duplicates of this line of code, nor is it in the first/last position. It's smack in the middle.

Now, in a fit of desperation, I renamed the actual file and line into "imag.png" And sure enough it worked! Lua could not find "image.png" but can find "imag.png"

And this repeats randomly everytime I add new lines into my lua script. Sometimes it affects other lines that worked before, but sometimes it doesn't.

Now my current problem is that I've been trying to do "loadfile()" in lua, and it doesn't find the .lua file I'm pointing to, even with absolute paths and Window-specific filepaths.

Any ideas?

Reply via email to