whelk/whelk.c
author J. Ali Harlow <ali@juiblex.co.uk>
Fri May 20 11:20:39 2016 +0100 (2016-05-20)
changeset 19 a659f35ffb54
parent 3 47fa028d40b3
child 21 285b05022b5a
permissions -rw-r--r--
Added tag 0.3.3 for changeset 30dd8888a271
     1 #include <stdlib.h>
     2 #include <string.h>
     3 #include <errno.h>
     4 #include <lua.h>
     5 #include <lualib.h>
     6 #include <lauxlib.h>
     7 #include "config.h"
     8 #include "_whelk.h"
     9 
    10 int whelk_perror(lua_State *L,const char *s)
    11 {
    12     lua_pushnil(L);
    13     if (s)
    14 	lua_pushfstring(L,"%s: %s",s,strerror(errno));
    15     else
    16 	lua_pushstring(L,strerror(errno));
    17     lua_pushinteger(L,errno);
    18     return 3;
    19 }
    20 
    21 static int whelk_unsupported(lua_State *L)
    22 {
    23     errno=ENOSYS;
    24     return whelk_perror(L,NULL);
    25 }
    26 
    27 #ifdef __WIN32__
    28 #define WIN32_ONLY(func)	func
    29 #else
    30 #define WIN32_ONLY(func)	whelk_unsupported
    31 #endif
    32 
    33 static const luaL_reg whelk_functions[]={
    34     { "GetFolderPath",WIN32_ONLY(whelk_get_folder_path) },
    35     { "CreateShortCut",WIN32_ONLY(whelk_create_short_cut) },
    36     { "Spawn",WIN32_ONLY(whelk_spawn) },
    37     { "CryptCATAdmin",WIN32_ONLY(whelk_crypt_cat_admin_new) },
    38     { "SetupCopyOEMInf",WIN32_ONLY(whelk_setup_copy_oem_inf) },
    39     { "SetupUninstallOEMInf",WIN32_ONLY(whelk_setup_uninstall_oem_inf) },
    40     { NULL }
    41 };
    42 
    43 LUALIB_API int luaopen_whelk(lua_State *L)
    44 {
    45     luaL_register(L,"whelk",whelk_functions);
    46     lua_pushliteral(L,"version");
    47     lua_pushliteral(L,PACKAGE_STRING);
    48     lua_settable(L,-3);
    49 #ifdef __WIN32__
    50     whelk_open_get_folder_path(L);
    51     whelk_open_reg_keys(L);
    52     whelk_open_setup(L);
    53 #endif
    54     return 1;
    55 }