[syslinux] [PATCH] Added functions config_file(), ipappend_strs(), and reboot() to Lua.c32.

Hung-chi Lihn hlihn at google.com
Sun Sep 23 09:42:57 PDT 2012


From: Hung-chi Lihn <hlihn at google.com>

This allows the Lua script to query the config file name and the ipappend
strings (pxelinux only), as well as to perform reboot (warm and cold)
to the system.

In Lua.c32, the extension will be used as the following:
  1. syslinux.config_file() will return the config file string.
  2. syslinux.ipappend_strs() will return a table of IPAPPEND strings with
     numerical indices.
  3. syslinux.reboot() will perform cold reboot, while syslinux.reboot(1)
     will perform warm reboot.
---
 com32/lua/src/syslinux.c |   33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/com32/lua/src/syslinux.c b/com32/lua/src/syslinux.c
index af5db83..afbccd4 100644
--- a/com32/lua/src/syslinux.c
+++ b/com32/lua/src/syslinux.c
@@ -39,6 +39,7 @@
 #include "syslinux/loadfile.h"
 #include "syslinux/linux.h"
 #include "syslinux/config.h"
+#include "syslinux/reboot.h"
 
 int __parse_argv(char ***argv, const char *str);
 
@@ -408,6 +409,35 @@ static int sl_boot_it(lua_State * L)
 			       initramfs, NULL, (char *)cmdline);
 }
 
+static int sl_config_file(lua_State * L)
+{
+    const char *config_file = syslinux_config_file();
+    lua_pushstring(L, config_file);
+    return 1;
+}
+
+static int sl_reboot(lua_State * L)
+{
+    int warm_boot = luaL_optint(L, 1, 0);
+    /* explicitly convert it to 1 or 0 */
+    warm_boot = warm_boot? 1 : 0;
+    syslinux_reboot(warm_boot);
+    return 0;
+}
+
+static int sl_ipappend_strs(lua_State * L)
+{
+    int i;
+    const struct syslinux_ipappend_strings *ip_strs = syslinux_ipappend_strings
+    lua_newtable(L);
+    for (i = 0; i < ip_strs->count; i++) {
+        lua_pushinteger(L, i + 1);
+        lua_pushstring(L, ip_strs->ptr[i]);
+        lua_settable(L,-3);
+    }
+    return 1;
+}
+
 static int sl_derivative(lua_State * L)
 {
     const struct syslinux_version *sv;
@@ -459,6 +489,9 @@ static const luaL_reg syslinuxlib[] = {
     {"initramfs_load_archive", sl_initramfs_load_archive},
     {"initramfs_add_file", sl_initramfs_add_file},
     {"boot_it", sl_boot_it},
+    {"config_file", sl_config_file},
+    {"ipappend_strs", sl_ipappend_strs},
+    {"reboot", sl_reboot},
     {"derivative", sl_derivative},
     {"version", sl_version},
     {NULL, NULL}
-- 
1.7.10.4




More information about the Syslinux mailing list