diff options
| author | Michael <[email protected]> | 2017-02-19 20:19:00 -0500 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-02-19 20:19:00 -0500 |
| commit | 994f6b991a56382f530e3d43ad1f3a56c195559d (patch) | |
| tree | 014d70e562cb584e4e592eb0bc9c680cacda007b /ShiftOS_TheReturn/Scripting.cs | |
| parent | 55c1fbeaa215fd2b2e65c51d0cd2aae53892f135 (diff) | |
| download | shiftos_thereturn-994f6b991a56382f530e3d43ad1f3a56c195559d.tar.gz shiftos_thereturn-994f6b991a56382f530e3d43ad1f3a56c195559d.tar.bz2 shiftos_thereturn-994f6b991a56382f530e3d43ad1f3a56c195559d.zip | |
SFT making utilities
Diffstat (limited to 'ShiftOS_TheReturn/Scripting.cs')
| -rw-r--r-- | ShiftOS_TheReturn/Scripting.cs | 42 |
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 { |
