Language: 
To browser these website, it's necessary to store cookies on your computer.
The cookies contain no personal information, they are required for program control.
  the storage of cookies while browsing this website, on Login and Register.

Author Topic:  A patch suggestion in plugin_lua.c (luaLoadFile)...  (Read 22786 times)

0 Members and 0 Guests are viewing this topic.

argh

« on: 26, November 2009, 00:26:49 »
Hi,

In fact, at the moment, I don't know if it is a true issue (tell me).

In plugin_lua.c, the luaLoadFile function is as follows:
Code: [Select]
/* Load 'file' */
static int luaLoadFile_old(lua_State *L, const char *file)
{
    const char *path = hooks->create_mapdir_pathname(file);
    int         res = 0;

    if ((res = luaFindFile(L, file, &path)) == 0)
    {
        if ((res = load_file_cache(L, path)) == 0)
        {
            lua_rawgeti(L, LUA_REGISTRYINDEX, cache_ref);
            lua_pushstring(L, file);
            lua_rawget(L, -2);

            if (!lua_isfunction(L, -1))
            {
                lua_pop(L, 1);
                lua_pushstring(L, file);
                lua_pushstring(L, path);
                lua_rawset(L, -3);
            }
            lua_pop(L, 1);
        }
    }
    return res;
}

The expected behaviour of this function is to put at the top of the lua stack the lua function loaded (or an error message).
If !lua_isfunction(L, -1) returns false (for the moment, I don't how it can occur), the stack will contain the cache table (at the top) and the lua function. From my point of view, the cache table should be removed from the top of the stack.

I would suggest the following correction:
Code: [Select]
/* Load 'file' */
static int luaLoadFile(lua_State *L, const char *file)
{
    const char *path = hooks->create_mapdir_pathname(file);
    int         res = 0;

    if ((res = luaFindFile(L, file, &path)) == 0)
    {
        if ((res = load_file_cache(L, path)) == 0)
        {
            lua_rawgeti(L, LUA_REGISTRYINDEX, cache_ref);

            lua_pushstring(L, file);
            lua_pushstring(L, path);
            lua_rawset(L, -3);

            lua_pop(L, 1);
        }
    }
    return res;
}

« Last Edit: 26, November 2009, 00:28:49 by argh »

michtoen

« Reply #1 on: 26, November 2009, 01:53:03 »
Wonder who worked last time on that... gecko?
vita est proelium

Mizza

« Reply #2 on: 14, January 2010, 23:22:22 »
23:19

giltux * r5373 /trunk/server/src/plugin_lua/plugin_lua.c:
Fix a minor issue concerning the lualoadfile function
https://www.daimonin.org/forums/bug-discussion/a-patch-suggesti on-in-plugin_lua-c-(lualoadfile)/

Tags:
 

Related Topics

  Subject / Started by Replies Last post
30 Replies
5976 Views
Last post 06, September 2007, 13:57:37
by longir
14 Replies
1719 Views
Last post 15, January 2007, 14:06:18
by Blair13
2 Replies
1811 Views
Last post 16, March 2007, 22:50:57
by Syber
9 Replies
2740 Views
Last post 26, July 2007, 14:45:14
by longir
6 Replies
2021 Views
Last post 15, October 2007, 23:38:48
by Anich