aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS_TheReturn')
-rw-r--r--ShiftOS_TheReturn/Scripting.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/ShiftOS_TheReturn/Scripting.cs b/ShiftOS_TheReturn/Scripting.cs
index cfa1549..3ecf9d9 100644
--- a/ShiftOS_TheReturn/Scripting.cs
+++ b/ShiftOS_TheReturn/Scripting.cs
@@ -63,6 +63,12 @@ namespace ShiftOS.Engine.Scripting
public dynamic Lua = new DynamicLua.DynamicLua();
public bool Running = true;
+ public static string CreateSft(string lua)
+ {
+ byte[] bytes = Encoding.UTF8.GetBytes(lua);
+ return Convert.ToBase64String(bytes);
+ }
+
public static void RunSft(string sft)
{
if (Utils.FileExists(sft))
@@ -72,6 +78,7 @@ namespace ShiftOS.Engine.Scripting
string b64 = Utils.ReadAllText(sft);
byte[] bytes = Convert.FromBase64String(b64);
string lua = Encoding.UTF8.GetString(bytes);
+ CurrentDirectory = sft.Replace(Utils.GetFileInfo(sft).Name, "");
new LuaInterpreter().Execute(lua);
}
catch
@@ -81,6 +88,8 @@ namespace ShiftOS.Engine.Scripting
}
}
+ public static string CurrentDirectory { get; private set; }
+
public LuaInterpreter()
{
Lua(@"function totable(clrlist)
@@ -101,6 +110,7 @@ end");
public void SetupAPIs()
{
+ Lua.currentdir = (string.IsNullOrWhiteSpace(CurrentDirectory)) ? "0:" : CurrentDirectory;
Lua.random = new Func<int, int, int>((min, max) =>
{
return new Random().Next(min, max);
@@ -208,6 +218,7 @@ end");
{
if (Utils.FileExists(file))
{
+ CurrentDirectory = file.Replace(Utils.GetFileInfo(file).Name, "");
Execute(Utils.ReadAllText(file));
}
else
@@ -248,6 +259,37 @@ end");
}
}
+ [Exposed("sft")]
+ public class SFTFunctions
+ {
+ public string make(string lua)
+ {
+ return LuaInterpreter.CreateSft(lua);
+ }
+
+ public void makefile(string lua, string outpath)
+ {
+ Utils.WriteAllText(outpath, make(lua));
+ }
+
+ public void run(string inpath)
+ {
+ LuaInterpreter.RunSft(inpath);
+ }
+
+ public string unmake(string sft)
+ {
+ if (Utils.FileExists(sft))
+ {
+ string b64 = Utils.ReadAllText(sft);
+ byte[] bytes = Convert.FromBase64String(b64);
+ string lua = Encoding.UTF8.GetString(bytes);
+ return lua;
+ }
+ return "";
+ }
+ }
+
[Exposed("net")]
public class NetFunctions
{