webmcp

diff libraries/extos/extos.c @ 64:3d43a5cf17c1

Compatibility with Lua 5.2
author jbe
date Sun Apr 15 16:04:33 2012 +0200 (2012-04-15)
parents 9fdfb27f8e67
children 593413f317f4
line diff
     1.1 --- a/libraries/extos/extos.c	Tue Apr 03 00:56:02 2012 +0200
     1.2 +++ b/libraries/extos/extos.c	Sun Apr 15 16:04:33 2012 +0200
     1.3 @@ -328,6 +328,15 @@
     1.4    return 1;
     1.5  }
     1.6  
     1.7 +static const struct luaL_Reg extos_module_functions[] = {
     1.8 +  {"pfilter",              extos_pfilter},
     1.9 +  {"listdir",              extos_listdir},
    1.10 +  {"crypt",                extos_crypt},
    1.11 +  {"hires_time",           extos_hires_time},
    1.12 +  {"monotonic_hires_time", extos_monotonic_hires_time},
    1.13 +  {NULL, NULL}
    1.14 +};
    1.15 +
    1.16  int luaopen_extos(lua_State *L) {
    1.17    {
    1.18      struct timespec tp;
    1.19 @@ -336,16 +345,11 @@
    1.20      }
    1.21      extos_monotonic_start_time = tp.tv_sec + 0.000000001 * tp.tv_nsec;
    1.22    }
    1.23 -  lua_getglobal(L, "os");
    1.24 -  lua_pushcfunction(L, extos_pfilter);
    1.25 -  lua_setfield(L, -2, "pfilter");
    1.26 -  lua_pushcfunction(L, extos_listdir);
    1.27 -  lua_setfield(L, -2, "listdir");
    1.28 -  lua_pushcfunction(L, extos_crypt);
    1.29 -  lua_setfield(L, -2, "crypt");
    1.30 -  lua_pushcfunction(L, extos_hires_time);
    1.31 -  lua_setfield(L, -2, "hires_time");
    1.32 -  lua_pushcfunction(L, extos_monotonic_hires_time);
    1.33 -  lua_setfield(L, -2, "monotonic_hires_time");
    1.34 -  return 0;
    1.35 +#if LUA_VERSION_NUM >= 502
    1.36 +  lua_newtable(L);
    1.37 +  luaL_setfuncs(L, extos_module_functions, 0);
    1.38 +#else
    1.39 +  luaL_register(L, lua_tostring(L, 1) || "extos", extos_module_functions);
    1.40 +#endif
    1.41 +  return 1;
    1.42  }

Impressum / About Us