aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lua
diff options
context:
space:
mode:
authorMarcel Ritter <unrzl1@linux.rrze.uni-erlangen.de>2008-12-15 08:53:58 +0100
committerMarcel Ritter <unrzl1@linux.rrze.uni-erlangen.de>2008-12-15 08:53:58 +0100
commitf06f55139583f1d0022e78805df6d23fa72ae7d0 (patch)
tree8283a4c03ba4936019b4d7ee0245358d60fbf0e6 /com32/lua
parent16fa94bd8c1556d7aae3942293cba0a2f61e4ce7 (diff)
downloadsyslinux-f06f55139583f1d0022e78805df6d23fa72ae7d0.tar.gz
syslinux-f06f55139583f1d0022e78805df6d23fa72ae7d0.tar.xz
syslinux-f06f55139583f1d0022e78805df6d23fa72ae7d0.zip
COM32: lua - added dmi functions
Diffstat (limited to 'com32/lua')
-rw-r--r--com32/lua/src/Makefile2
-rw-r--r--com32/lua/src/dmi.c299
-rw-r--r--com32/lua/src/linit.c1
-rw-r--r--com32/lua/src/lualib.h2
-rw-r--r--com32/lua/test/dmi.lua21
5 files changed, 324 insertions, 1 deletions
diff --git a/com32/lua/src/Makefile b/com32/lua/src/Makefile
index f9e0ab32..07ae9e6b 100644
--- a/com32/lua/src/Makefile
+++ b/com32/lua/src/Makefile
@@ -52,7 +52,7 @@ LIBLUA_OBJS += syslinux.o
LIBLUA_OBJS += lauxlib.o lbaselib.o ldblib.o ltablib.o \
lstrlib.o loadlib.o linit.o
LIBLUA_OBJS += liolib.o
-
+LIBLUA_OBJS += dmi.o ../../modules/dmi.o
CFLAGS += -DLUA_ANSI
diff --git a/com32/lua/src/dmi.c b/com32/lua/src/dmi.c
new file mode 100644
index 00000000..b1337401
--- /dev/null
+++ b/com32/lua/src/dmi.c
@@ -0,0 +1,299 @@
+#include <stdlib.h>
+#include <string.h>
+
+#define ldmilib_c /* Define the library */
+
+/* Include the Lua API header files */
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+#include "dmi/dmi.h"
+
+static int dmi_gettable(lua_State *L)
+{
+ s_dmi dmi;
+
+ lua_newtable(L);
+
+ if ( ! dmi_interate() ) {
+ printf("No DMI Structure found\n");
+ return -1;
+ }
+
+ parse_dmitable(&dmi);
+
+ /* bios */
+ lua_pushstring(L, "bios.vendor");
+ lua_pushstring(L, dmi.bios.vendor);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "bios.version");
+ lua_pushstring(L, dmi.bios.version);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "bios.release_date");
+ lua_pushstring(L, dmi.bios.release_date);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "bios.bios_revision");
+ lua_pushstring(L, dmi.bios.bios_revision);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "bios.firmware_revision");
+ lua_pushstring(L, dmi.bios.firmware_revision);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "bios.address");
+ lua_pushnumber(L, dmi.bios.address);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "bios.runtime_size");
+ lua_pushnumber(L, dmi.bios.runtime_size);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "bios.runtime_size_unit");
+ lua_pushstring(L, dmi.bios.runtime_size_unit);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "bios.rom_size");
+ lua_pushnumber(L, dmi.bios.rom_size);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "bios.rom_size_unit");
+ lua_pushstring(L, dmi.bios.rom_size_unit);
+ lua_settable(L,-3);
+
+ /* system */
+ lua_pushstring(L, "system.manufacturer");
+ lua_pushstring(L, dmi.system.manufacturer);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "system.product_name");
+ lua_pushstring(L, dmi.system.product_name);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "system.version");
+ lua_pushstring(L, dmi.system.version);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "system.serial");
+ lua_pushstring(L, dmi.system.serial);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "system.uuid");
+ lua_pushstring(L, dmi.system.uuid);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "system.wakeup_type");
+ lua_pushstring(L, dmi.system.wakeup_type);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "system.sku_number");
+ lua_pushstring(L, dmi.system.sku_number);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "system.family");
+ lua_pushstring(L, dmi.system.family);
+ lua_settable(L,-3);
+
+ /* base_board */
+ lua_pushstring(L, "base_board.manufacturer");
+ lua_pushstring(L, dmi.base_board.manufacturer);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "base_board.product_name");
+ lua_pushstring(L, dmi.base_board.product_name);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "base_board.version");
+ lua_pushstring(L, dmi.base_board.version);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "base_board.serial");
+ lua_pushstring(L, dmi.base_board.serial);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "base_board.asset_tag");
+ lua_pushstring(L, dmi.base_board.asset_tag);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "base_board.location");
+ lua_pushstring(L, dmi.base_board.location);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "base_board.type");
+ lua_pushstring(L, dmi.base_board.type);
+ lua_settable(L,-3);
+
+ /* chassis */
+ lua_pushstring(L, "chassis.manufacturer");
+ lua_pushstring(L, dmi.chassis.manufacturer);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "chassis.type");
+ lua_pushstring(L, dmi.chassis.type);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "chassis.lock");
+ lua_pushstring(L, dmi.chassis.lock);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "chassis.version");
+ lua_pushstring(L, dmi.chassis.version);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "chassis.serial");
+ lua_pushstring(L, dmi.chassis.serial);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "chassis.asset_tag");
+ lua_pushstring(L, dmi.chassis.asset_tag);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "chassis.boot_up_state");
+ lua_pushstring(L, dmi.chassis.boot_up_state);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "chassis.power_supply_state");
+ lua_pushstring(L, dmi.chassis.power_supply_state);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "chassis.thermal_state");
+ lua_pushstring(L, dmi.chassis.thermal_state);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "chassis.security_status");
+ lua_pushstring(L, dmi.chassis.security_status);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "chassis.oem_information");
+ lua_pushstring(L, dmi.chassis.oem_information);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "chassis.height");
+ lua_pushnumber(L, dmi.chassis.height);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "chassis.nb_power_cords");
+ lua_pushnumber(L, dmi.chassis.nb_power_cords);
+ lua_settable(L,-3);
+
+ /* processor */
+ lua_pushstring(L, "processor.socket_designation");
+ lua_pushstring(L, dmi.processor.socket_designation);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.type");
+ lua_pushstring(L, dmi.processor.type);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.family");
+ lua_pushstring(L, dmi.processor.family);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.manufacturer");
+ lua_pushstring(L, dmi.processor.manufacturer);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.version");
+ lua_pushstring(L, dmi.processor.version);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.external_clock");
+ lua_pushnumber(L, dmi.processor.external_clock);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.max_speed");
+ lua_pushnumber(L, dmi.processor.max_speed);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.current_speed");
+ lua_pushnumber(L, dmi.processor.current_speed);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.signature.type");
+ lua_pushnumber(L, dmi.processor.signature.type);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.signature.family");
+ lua_pushnumber(L, dmi.processor.signature.family);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.signature.model");
+ lua_pushnumber(L, dmi.processor.signature.model);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.signature.stepping");
+ lua_pushnumber(L, dmi.processor.signature.stepping);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.signature.minor_stepping");
+ lua_pushnumber(L, dmi.processor.signature.minor_stepping);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.voltage");
+ lua_pushnumber(L, dmi.processor.voltage);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.status");
+ lua_pushstring(L, dmi.processor.status);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.upgrade");
+ lua_pushstring(L, dmi.processor.upgrade);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.cache1");
+ lua_pushstring(L, dmi.processor.cache1);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.cache2");
+ lua_pushstring(L, dmi.processor.cache2);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.cache3");
+ lua_pushstring(L, dmi.processor.cache3);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.serial");
+ lua_pushstring(L, dmi.processor.serial);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.part_number");
+ lua_pushstring(L, dmi.processor.part_number);
+ lua_settable(L,-3);
+
+ lua_pushstring(L, "processor.id");
+ lua_pushstring(L, dmi.processor.id);
+ lua_settable(L,-3);
+
+ /* set global variable: lua_setglobal(L, "dmitable"); */
+
+ /* return number of return values on stack */
+ return 1;
+}
+
+
+static int dmi_supported(lua_State *L)
+{
+ if ( dmi_interate() ) {
+ lua_pushboolean(L, 1);
+ } else {
+ lua_pushboolean(L, 0);
+ }
+ return 1;
+}
+
+
+static const luaL_Reg dmilib[] = {
+ {"gettable", dmi_gettable},
+ {"supported", dmi_supported},
+ {NULL, NULL}
+};
+
+
+LUALIB_API int luaopen_dmi (lua_State *L) {
+ luaL_openlib(L, LUA_DMILIBNAME, dmilib, 0);
+ return 1;
+}
+
diff --git a/com32/lua/src/linit.c b/com32/lua/src/linit.c
index 04d2b550..e457ee8d 100644
--- a/com32/lua/src/linit.c
+++ b/com32/lua/src/linit.c
@@ -25,6 +25,7 @@ static const luaL_Reg lualibs[] = {
{LUA_MATHLIBNAME, luaopen_math},
#endif
{LUA_DBLIBNAME, luaopen_debug},
+ {LUA_DMILIBNAME, luaopen_dmi},
{LUA_SYSLINUXLIBNAME, luaopen_syslinux},
{NULL, NULL}
};
diff --git a/com32/lua/src/lualib.h b/com32/lua/src/lualib.h
index 2aa93246..8e220ef1 100644
--- a/com32/lua/src/lualib.h
+++ b/com32/lua/src/lualib.h
@@ -42,6 +42,8 @@ LUALIB_API int (luaopen_package) (lua_State *L);
#define LUA_SYSLINUXLIBNAME "syslinux"
LUALIB_API int (luaopen_syslinux) (lua_State *L);
+#define LUA_DMILIBNAME "dmi"
+LUALIB_API int (luaopen_dmi) (lua_State *L);
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);
diff --git a/com32/lua/test/dmi.lua b/com32/lua/test/dmi.lua
new file mode 100644
index 00000000..0f5526c7
--- /dev/null
+++ b/com32/lua/test/dmi.lua
@@ -0,0 +1,21 @@
+if (dmi.supported()) then
+
+ dmitable = dmi.gettable()
+
+ for k,v in pairs(dmitable) do
+ print(k, v)
+ end
+
+ print(dmitable["system.manufacturer"])
+ print(dmitable["system.product_name"])
+ print(dmitable["bios.bios_revision"])
+
+ if ( string.match(dmitable["system.product_name"], "ESPRIMO P7935") ) then
+ print("Matches")
+ syslinux.run_command("memdisk initrd=/dos/BIOS/FSC-P7935-108.img raw")
+ else
+ print("Does not match")
+ end
+
+end
+