mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-03-03 15:30:27 +00:00
添加Lua对环境变量的支持
This commit is contained in:
@@ -2,7 +2,8 @@
|
|||||||
namespace UniLua
|
namespace UniLua
|
||||||
{
|
{
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using CMLeonOS;
|
||||||
|
|
||||||
internal class LuaOSLib
|
internal class LuaOSLib
|
||||||
{
|
{
|
||||||
public const string LIB_NAME = "os";
|
public const string LIB_NAME = "os";
|
||||||
@@ -14,6 +15,10 @@ namespace UniLua
|
|||||||
#if !UNITY_WEBPLAYER
|
#if !UNITY_WEBPLAYER
|
||||||
new NameFuncPair("clock", OS_Clock),
|
new NameFuncPair("clock", OS_Clock),
|
||||||
new NameFuncPair("gethostname", OS_Gethostname),
|
new NameFuncPair("gethostname", OS_Gethostname),
|
||||||
|
new NameFuncPair("getenv", OS_Getenv),
|
||||||
|
new NameFuncPair("setenv", OS_Setenv),
|
||||||
|
new NameFuncPair("delenv", OS_Delenv),
|
||||||
|
new NameFuncPair("addenv", OS_Addenv),
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -34,6 +39,47 @@ namespace UniLua
|
|||||||
lua.PushString(hostname);
|
lua.PushString(hostname);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int OS_Getenv( ILuaState lua )
|
||||||
|
{
|
||||||
|
string varName = lua.L_CheckString(1);
|
||||||
|
string varValue = EnvironmentVariableManager.Instance.GetVariable(varName);
|
||||||
|
if (varValue == null)
|
||||||
|
{
|
||||||
|
lua.PushNil();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua.PushString(varValue);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int OS_Setenv( ILuaState lua )
|
||||||
|
{
|
||||||
|
string varName = lua.L_CheckString(1);
|
||||||
|
string varValue = lua.L_CheckString(2);
|
||||||
|
EnvironmentVariableManager.Instance.SetVariable(varName, varValue);
|
||||||
|
lua.PushBoolean(true);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int OS_Delenv( ILuaState lua )
|
||||||
|
{
|
||||||
|
string varName = lua.L_CheckString(1);
|
||||||
|
bool success = EnvironmentVariableManager.Instance.DeleteVariable(varName);
|
||||||
|
lua.PushBoolean(success);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int OS_Addenv( ILuaState lua )
|
||||||
|
{
|
||||||
|
string varName = lua.L_CheckString(1);
|
||||||
|
string varValue = lua.L_CheckString(2);
|
||||||
|
EnvironmentVariableManager.Instance.SetVariable(varName, varValue);
|
||||||
|
lua.PushBoolean(true);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user