summaryrefslogtreecommitdiff
path: root/lua/local/userconfig.c
diff options
context:
space:
mode:
Diffstat (limited to 'lua/local/userconfig.c')
-rw-r--r--lua/local/userconfig.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/lua/local/userconfig.c b/lua/local/userconfig.c
new file mode 100644
index 000000000..dfd2598d7
--- /dev/null
+++ b/lua/local/userconfig.c
@@ -0,0 +1,55 @@
+
+#include "config.h"
+
+#include "lposix.h"
+#include "lrexlib.h"
+
+#define LUA_EXTRALIBS \
+ {"posix", luaopen_posix}, \
+ {"rex", luaopen_rex}, \
+ {"luapath", luapath},
+
+#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);
+ }
+ }
+}
+
+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;
+}