lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



The difference is that gluax hides the table writing into just two lines:

        glua_pushTable();
			...
	        glua_setTable_str_i( ++n, name );

whereas the regular Lua stack handling needs these:

        lua_newtable(L);
			...
            lua_pushnumber(L, ++i);
            lua_pushstring(L, entry->d_name);
            lua_settable(L, -3);

(the setting of 'n' can be ignored)



PINELLI Thierry SGAP Marseille kirjoittaa maanantaina, 29. syyskuuta 2003, kello 17:32:

Le Mon, Sep 29, 2003 at 05:11:24PM +0300, you write :


Both LuaCheia and GluaX provide the kind of service you mention, and it
works for Linux, Win32 and OS X. From gluax 'sys_module.c' (returns a
table using gluax macros):

[...]

    struct dirent* entry;
        dir= opendir( path );
            while( (entry= readdir(dir)) != NULL )

        closedir( dir );

Look at lposlib.c you can read :

What's the difference ?


static int pos_dir (lua_State *L)
{
    DIR *d = NULL;

    switch (lua_type(L, 1))
    {
        case LUA_TNONE:
        d=opendir(".");
        break;

        case LUA_TSTRING:
        d=opendir(lua_tostring(L, 1));
        break;

        default:
lua_error(L, "optional argument to function Dir must be string");
    }
    if (d == NULL)
    {
        return pos_pusherr(L);
    }
    else
    {
        int i = 0;
        struct dirent *entry;
        lua_newtable(L);
        while ((entry = readdir(d)) != NULL)
        {
            lua_pushnumber(L, ++i);
            lua_pushstring(L, entry->d_name);
            lua_settable(L, -3);
        }
        closedir(d);
        lua_pushstring(L, "n");
        lua_pushnumber(L, i);
        lua_settable(L, -3);

        return 1;
    }
}