summaryrefslogtreecommitdiff
path: root/luaext/userconfig.c
blob: 014e325366ffa3652982a81fc07ca0cff790ea98 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

#include "config.h"

#include "lposix.h"
#include "lrexlib.h"

#define LUA_EXTRALIBS \
	{"posix", luaopen_posix}, \
	{"rex", luaopen_rex}, \
	{"luapath", luapath},

#if 0

#define lua_readline	myreadline
#define lua_saveline	mysaveline

#include <ctype.h>
#include <readline/readline.h>
#include <readline/history.h>

static int myreadline (lua_State *L, const char *prompt) {
  char *s=readline(prompt);
  if (s==NULL)
    return 0;
  else {
    lua_pushstring(L,s);
    lua_pushliteral(L,"\n");
    lua_concat(L,2);
    free(s);
    return 1;
  }
}

static void mysaveline (lua_State *L, const char *s) {
  const char *p;
  for (p=s; isspace(*p); p++);
  if (*p!=0) {
    size_t n=strlen(s)-1;
    if (s[n]!='\n')
      add_history(s);
    else {
      lua_pushlstring(L,s,n);
      s=lua_tostring(L,-1);
      add_history(s);
      lua_remove(L,-1);
    }
  }
}
#endif

static int luapath(lua_State *L)
{
	lua_pushstring(L, "LUA_PATH");
	lua_pushstring(L, RPMCONFIGDIR "/lua/?.lua;?.lua");
	lua_rawset(L, LUA_GLOBALSINDEX);
	return 0;
}