summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.mingw324
-rw-r--r--lua-interface-light.lua148
-rw-r--r--src/lua-interface.cpp43
3 files changed, 172 insertions, 23 deletions
diff --git a/Makefile.mingw32 b/Makefile.mingw32
index 44e6b4b..2924983 100644
--- a/Makefile.mingw32
+++ b/Makefile.mingw32
@@ -162,6 +162,7 @@ dblib.lua \
LuaSmtp.cc \
lua-plugin.cc \
lua-interface-hc.c \
+lua-interface-light-hc.c \
WHOLE_SOURCES = $(BALTISOT_SOURCES) $(LUA_SOURCES) $(LUAINTERFACE_SOURCES)
@@ -216,6 +217,9 @@ clean:
lua-interface-hc.c : lua-interface.lua
bin2c $< $@ lua_interface_lua
+lua-interface-light-hc.c : lua-interface-light.lua
+ bin2c $< $@ lua_interface_light_lua
+
%.c : %.lua
bin2c $< $@ $(basename $@)
diff --git a/lua-interface-light.lua b/lua-interface-light.lua
new file mode 100644
index 0000000..f4a019d
--- /dev/null
+++ b/lua-interface-light.lua
@@ -0,0 +1,148 @@
+loadmodule "luaiup"
+loadmodule "luahandle"
+
+local equivalent_locales = {
+ ["French"] = "frFR",
+ ["FranÃais"] = "frFR",
+ ["fr_FR"] = "frFR",
+ ["fr_BE"] = "frFR",
+}
+
+local invite_locale = {
+ ["default"] = "Please input .paq file to run",
+ ["frFR"] = "Saisissez le fichier .paq pour continuer",
+}
+
+local ok_locale = {
+ ["default"] = "Ok",
+ ["frFR"] = "Ok",
+}
+
+local quit_locale = {
+ ["default"] = "Quit",
+ ["frFR"] = "Quitter",
+}
+
+local error_not_archive_locale = {
+ ["default"] = "Wrong archive file type",
+ ["frFR"] = "Mauvais type d'archive .paq",
+}
+
+local error_wrong_archive_locale = {
+ ["default"] = "Archive doesn't contain archive_main.lua",
+ ["frFR"] = "L'archive ne contient pas archive_main.lua",
+}
+
+local error_bad_lua_locale = {
+ ["default"] = "archive_main.lua doesn't contain a archive_main function",
+ ["frFR"] = "archive_main.lua ne contient pas de fonction archive_main",
+}
+
+local okay = false
+local system_locale
+
+local input_file_text
+
+local function generate_dlg()
+ input_file_text = iup.text {
+ expand = "Horizontal",
+ }
+ local input_file_btn = iup.button { title = "..." }
+ local invite = invite_locale.default
+ system_locale = iup.GetGlobal "SYSTEMLANGUAGE"
+ if type(system_locale) == "string" then
+ local direct = invite_locale[system_locale]
+ if direct then
+ invite = direct
+ else
+ system_locale = equivalent_locales[system_locale]
+ if system_locale then
+ invite = invite_locale[system_locale]
+ else
+ system_locale = "default"
+ end
+ end
+ else
+ system_locale = "default"
+ end
+
+ function input_file_btn:action()
+ local filedlg = iup.filedlg {
+ filter = "*.paq",
+ title = invite,
+ }
+ filedlg:popup()
+
+ if filedlg.status + 0 == 0 then
+ input_file_text.value = filedlg.value
+ end
+
+ return iup.DEFAULT
+ end
+
+ local ok_btn = iup.button { title = ok_locale[system_locale] }
+ function ok_btn:action()
+ okay = true
+ return iup.CLOSE
+ end
+ local quit_btn = iup.button { title = quit_locale[system_locale] }
+ function quit_btn:action()
+ return iup.CLOSE
+ end
+
+ return iup.dialog {
+ iup.vbox {
+ iup.hbox {
+ iup.fill{},
+ iup.label { title = "Lua Interface Light", font = "Arial Bold 18" },
+ iup.fill{},
+ },
+ iup.fill { size = "x8" },
+ iup.label { title = invite },
+ iup.hbox {
+ input_file_text,
+ input_file_btn,
+ },
+ iup.fill { size = "x16" },
+ iup.hbox {
+ ok_btn,
+ iup.fill{},
+ quit_btn,
+
+ normalizesize = "Horizontal",
+ }
+ },
+
+ resize = "No",
+ maxbox = "No",
+ minbox = "No",
+ title = "Lua Interface Light",
+ gap = "2",
+ defaultesc = quit_btn,
+ toolbox = "Yes",
+ margin = "10x10",
+ size = "200x",
+ }
+end
+
+function lua_interface_light_main()
+ local dlg = generate_dlg()
+
+ dlg:show()
+ iup.MainLoop()
+ dlg:hide()
+
+ if not okay then return end
+
+ if not pcall(Archive(input_file_text.value)) then
+ error(error_not_archive_locale[system_locale])
+ end
+ if not pcall(load "archive_main.lua") then
+ error(error_wrong_archive_locale[system_locale])
+ end
+ if not type(archive_main) == "function" then
+ error(error_bad_lua_locale[system_locale])
+ end
+
+ archive_main()
+end
diff --git a/src/lua-interface.cpp b/src/lua-interface.cpp
index c8e5c24..9bf0e91 100644
--- a/src/lua-interface.cpp
+++ b/src/lua-interface.cpp
@@ -89,6 +89,8 @@ extern void luaiup_init(Lua * L) WEAK;
#endif
#ifdef LUA_INTERFACE_LIGHT
+extern unsigned int size_lua_interface_light_lua;
+extern unsigned char lua_interface_light_lua[];
#define MODULES_BUILT_IN
#define LIGHT "-light"
#else
@@ -524,8 +526,6 @@ struct option long_options[] = {
{"help", 0, NULL, 'h'},
{"verbose", 0, NULL, 'v'},
{"archive", 1, NULL, 'a'},
- {"compile", 1, NULL, 'c'},
- {"debug", 0, NULL, 'd'},
{"interactive", 0, NULL, 'i'},
{"line", 0, NULL, 'l'},
{"exec", 1, NULL, 'e'},
@@ -666,8 +666,6 @@ void showhelp(bool longhelp = false) {
"Options:\n"
" -v for verbose mode.\n"
" -a <paq> to load an additionnal archive file.\n"
-" -c <out> to dump the compiled byte code to file.\n"
-" -d to enable debug mode (ie, do not strip)\n"
" -i to start interactive mode.\n"
" -l to turn off the exec on end line.\n"
" -e <cmd> to execute this single command in LUA.\n"
@@ -846,8 +844,8 @@ void autoload_exports(Lua * L) {
virtual int startup() throw (GeneralException) {
char c;
- bool strip = true, todo = false, write = false, builtin = false, daemonize = false;
- char * file = 0, * output = 0, * compile = 0, * exec = 0;
+ bool todo = false, write = false, builtin = false, daemonize = false;
+ char * file = 0, * output = 0, * exec = 0;
Lua * L = 0;
String hport = "1500", tport = "1550", mport = "2500";
pthread_t interactive_thread;
@@ -860,7 +858,7 @@ virtual int startup() throw (GeneralException) {
/* Let's start parsing options */
- while ((c = getopt_long(argc, argv, "Hhva:c:dile:bg:m::s::t::f:z", long_options, NULL)) != EOF) {
+ while ((c = getopt_long(argc, argv, "Hhva:ile:bg:m::s::t::f:z", long_options, NULL)) != EOF) {
switch (c) {
case 'h':
case 'H':
@@ -873,12 +871,6 @@ virtual int startup() throw (GeneralException) {
case 'a':
new Archive(optarg);
break;
- case 'c':
- compile = strdup(optarg);
- break;
- case 'd':
- strip = false;
- break;
case 'i':
interactive = true;
todo = true;
@@ -951,8 +943,8 @@ virtual int startup() throw (GeneralException) {
showjitstatus(L);
- /* Loading lua-interface.lua (only when not compiling) */
- if (!compile && !builtin) {
+ /* Loading lua-interface.lua */
+ if (!builtin) {
try {
L->load(&Input("lua-interface.lua"));
}
@@ -962,7 +954,7 @@ virtual int startup() throw (GeneralException) {
}
}
- if (!compile && builtin) {
+ if (builtin) {
Buffer built;
built.write(lua_interface_lua, size_lua_interface_lua);
@@ -980,16 +972,21 @@ virtual int startup() throw (GeneralException) {
L->load(&Input(argv[optind++]), !compile);
}
- /* Doh... */
if (!todo) {
+#ifdef LUA_INTERFACE_LIGHT
+ Buffer built;
+ built.write(lua_interface_light_lua, size_lua_interface_light_lua);
+
+ try {
+ L->load(&built);
+ }
+ catch (GeneralException e) {
+ printm(M_WARNING, "There was an error loading built-in lua-interface-light.lua: %s\n", e.GetMsg());
+ }
+#else
showhelp();
throw Exit(0);
- }
-
- /* Compilation process will exit from itself right after */
- if (compile) {
- L->dump(&Output(compile), strip);
- throw Exit(0);
+#endif
}
/* One shot command */