summaryrefslogtreecommitdiff
path: root/lwinlib.c (plain)
blob: bd5cab2248dd5726bbc00899f4860f1d920b662f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <lua.h>
#include <lauxlib.h>

#ifdef _WIN32
#include <shlobj.h>
#endif

int get_appdata(lua_State *L) {
#ifdef _WIN32
  char pbuf[MAX_PATH];
  if(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, pbuf) == S_OK)
    lua_pushstring(L, pbuf);
  else
    lua_pushnil(L);
#else
  lua_pushnil(L);
#endif
  return 1;
}

int luaopen_win(lua_State *L) {
  const struct luaL_Reg win[] = {
    { "appdata", get_appdata },
    { NULL, NULL }
  };
  luaL_register(L, "win", win);
  return 1;
}