summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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() {