diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/BLua.cc | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc index 76cd443..5ff970e 100644 --- a/lib/BLua.cc +++ b/lib/BLua.cc @@ -339,8 +339,22 @@ int LuaStatics::getenv(lua_State * _L) { if (n != 1) { L->error("Incorrect arguments to function `getenv'"); } - - L->push(::getenv(L->tostring(1).to_charp())); + +#ifdef _WIN32 + char buffer[BUFSIZ + 1]; + if (GetEnvironmentVariable(L->tostring(1).to_charp(), buffer, BUFSIZ)) { + L->push(buffer); + } else { + L->push(); + } +#else + char * var = ::getenv(L->tostring(1).to_charp()); + if (var) { + L->push(var); + } else { + L->push(); + } +#endif return 1; } @@ -352,8 +366,12 @@ int LuaStatics::setenv(lua_State * _L) { if (n != 2) { L->error("Incorrect arguments to function `setenv'"); } - + +#ifdef _WIN32 + SetEnvironmentVariable(L->tostring(1).to_charp(), L->tostring(2).to_charp()); +#else ::setenv(L->tostring(1).to_charp(), L->tostring(2).to_charp(), 1); +#endif return 0; } @@ -365,8 +383,12 @@ int LuaStatics::unsetenv(lua_State * _L) { if (n != 1) { L->error("Incorrect arguments to function `unsetenv'"); } - + +#ifdef _WIN32 + SetEnvironmentVariable(L->tostring(1).to_charp(), NULL); +#else ::unsetenv(L->tostring(1).to_charp()); +#endif return 0; } |