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