summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-07-07 09:56:30 -0700
committerPixel <pixel@nobis-crew.org>2009-07-07 09:56:30 -0700
commit6d1dee65d5ad695670d73bf3e162b4b6e984af35 (patch)
treeb80d29a562b37453eb7ac2da2dd8c4c31a48d707
parent8ff7d0e2071eea172725edfe3ce19953bf4a55da (diff)
Adding get/set/unsetenv to Lua.
-rw-r--r--lib/BLua.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc
index 7a85b07..f7f8d53 100644
--- a/lib/BLua.cc
+++ b/lib/BLua.cc
@@ -85,6 +85,9 @@ class LuaStatics : public Base {
static int iconv(lua_State *);
static int mkdir(lua_State *);
static int time(lua_State *);
+ static int getenv(lua_State *);
+ static int setenv(lua_State *);
+ static int unsetenv(lua_State *);
static int globalindex(lua_State *);
@@ -327,6 +330,45 @@ int LuaStatics::time(lua_State * _L) {
return 1;
}
+int LuaStatics::getenv(lua_State * _L) {
+ Lua * L = Lua::find(_L);
+
+ int n = L->gettop(); /* number of arguments */
+ if (n != 1) {
+ L->error("Incorrect arguments to function `getenv'");
+ }
+
+ L->push(::getenv(L->tostring(1).to_charp()));
+
+ return 1;
+}
+
+int LuaStatics::setenv(lua_State * _L) {
+ Lua * L = Lua::find(_L);
+
+ int n = L->gettop(); /* number of arguments */
+ if (n != 2) {
+ L->error("Incorrect arguments to function `setenv'");
+ }
+
+ ::setenv(L->tostring(1).to_charp(), L->tostring(2).to_charp(), 1);
+
+ return 0;
+}
+
+int LuaStatics::unsetenv(lua_State * _L) {
+ Lua * L = Lua::find(_L);
+
+ int n = L->gettop(); /* number of arguments */
+ if (n != 1) {
+ L->error("Incorrect arguments to function `setenv'");
+ }
+
+ ::unsetenv(L->tostring(1).to_charp());
+
+ return 0;
+}
+
int LuaStatics::print(lua_State * _L) {
Lua * L = Lua::find(_L);
@@ -505,6 +547,15 @@ void Lua::open_base() {
push("time");
push(LuaStatics::time);
settable(LUA_GLOBALSINDEX);
+ push("getenv");
+ push(LuaStatics::getenv);
+ settable(LUA_GLOBALSINDEX);
+ push("setenv");
+ push(LuaStatics::setenv);
+ settable(LUA_GLOBALSINDEX);
+ push("unsetenv");
+ push(LuaStatics::unsetenv);
+ settable(LUA_GLOBALSINDEX);
}
void Lua::open_table() {