whelk/whelk.c
changeset 0 8525965e930d
child 3 47fa028d40b3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/whelk/whelk.c	Thu Jul 09 08:52:03 2009 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +#include <stdlib.h>
     1.5 +#include <string.h>
     1.6 +#include <errno.h>
     1.7 +#include <lua.h>
     1.8 +#include <lualib.h>
     1.9 +#include <lauxlib.h>
    1.10 +#include "config.h"
    1.11 +#include "_whelk.h"
    1.12 +
    1.13 +int whelk_perror(lua_State *L,const char *s)
    1.14 +{
    1.15 +    lua_pushnil(L);
    1.16 +    if (s)
    1.17 +	lua_pushfstring(L,"%s: %s",s,strerror(errno));
    1.18 +    else
    1.19 +	lua_pushstring(L,strerror(errno));
    1.20 +    lua_pushinteger(L,errno);
    1.21 +    return 3;
    1.22 +}
    1.23 +
    1.24 +static int whelk_unsupported(lua_State *L)
    1.25 +{
    1.26 +    errno=ENOSYS;
    1.27 +    return whelk_perror(L,NULL);
    1.28 +}
    1.29 +
    1.30 +#ifdef __WIN32__
    1.31 +#define WIN32_ONLY(func)	func
    1.32 +#else
    1.33 +#define WIN32_ONLY(func)	whelk_unsupported
    1.34 +#endif
    1.35 +
    1.36 +static const luaL_reg whelk_functions[]={
    1.37 +    { "GetFolderPath",WIN32_ONLY(whelk_get_folder_path) },
    1.38 +    { "CreateShortCut",WIN32_ONLY(whelk_create_short_cut) },
    1.39 +    { NULL }
    1.40 +};
    1.41 +
    1.42 +LUALIB_API int luaopen_whelk(lua_State *L)
    1.43 +{
    1.44 +    luaL_register(L,"whelk",whelk_functions);
    1.45 +    lua_pushliteral(L,"version");
    1.46 +    lua_pushliteral(L,PACKAGE_STRING);
    1.47 +    lua_settable(L,-3);
    1.48 +#ifdef __WIN32__
    1.49 +    whelk_open_get_folder_path(L);
    1.50 +    whelk_open_reg_keys(L);
    1.51 +#endif
    1.52 +    return 1;
    1.53 +}