socsvn commit: r269831 - soc2014/pedrosouza/lua_loader/head/sys/boot/lua

pedrosouza at FreeBSD.org pedrosouza at FreeBSD.org
Sat Jun 21 21:29:13 UTC 2014


Author: pedrosouza
Date: Sat Jun 21 21:29:11 2014
New Revision: 269831
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=269831

Log:
  Added getenv function to lua

Modified:
  soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c

Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c	Sat Jun 21 19:29:40 2014	(r269830)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c	Sat Jun 21 21:29:11 2014	(r269831)
@@ -112,6 +112,22 @@
 	return 0;
 }
 
+int lua_getenv(lua_State * L)
+{
+	char * ev;
+	int n = lua_gettop(L);
+	if (n == 1)
+	{
+		ev = getenv(lua_tostring(L, 1));
+		if (ev != NULL)
+			lua_pushstring(L, ev);
+		else
+			lua_pushnil(L);
+	} else
+		lua_pushnil(L);
+	return 1;
+}
+
 void *
 lua_realloc(void *ud, void *ptr, size_t osize, size_t nsize)
 {
@@ -149,7 +165,7 @@
 	data_chunk ds;
 	ds.data = (void*)str;
 	ds.size = size;
-	res = lua_load(L, read_chunk, &ds, "do_string_", 0);
+	res = lua_load(L, read_chunk, &ds, "do_string", 0);
 	res = lua_pcall(L, 0, LUA_MULTRET, 0);
 	return res;
 }
@@ -246,6 +262,7 @@
 			{lua_perform, "loader", "perform"},
 			{lua_delay, "loader", "delay"},
 			{lua_include, "loader", "include"},
+			{lua_getenv, "loader", "getenv"},
 			{lua_strchar, "string", "byte"},
 			{lua_charstr, "string", "char"},
 			{lua_getchar, "io", "getchar"},


More information about the svn-soc-all mailing list