Skip to content

Commit

Permalink
fix code duplicates and improve overall code readability and structure
Browse files Browse the repository at this point in the history
  • Loading branch information
albertotirla committed Jan 22, 2021
1 parent b0e89e2 commit 51ac440
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
17 changes: 9 additions & 8 deletions autoaccess/autoaccess/RunCodePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ public RunCodePage( string Code="")
private void InitLua()
{
LuaState = new Lua();
// LuaState["__page__"]=this;
const string PrintFunctionCode = "function print(message) __page__:DisplayAlert(\"program output\", tostring(message), \"OK\") end";
LuaState.LoadCLRPackage();
LuaState.DoString(PrintFunctionCode);
LuaState.RegisterFunction("print", this, this.GetType().GetMethod("print"));

LuaState["tts"]=new tts();
//LuaState.RegisterFunction("vibrate", this.GetType().GetMethod("Vibrate"));
LuaState["PowerIndicator"] = new PowerIndicator();
LuaState["VibrationService"] = new VibrationService();
}
public static async void speak(Object MessageToSpeak)
}
public async void print(params object[] values)
{
await TextToSpeech.SpeakAsync(MessageToSpeak.ToString());
StringBuilder sb = new StringBuilder();
foreach(var param in values)
{
sb.Append(param.ToString() + "\n");
}
await DisplayAlert("program output", sb.ToString(), "OK");
}
async void btnStartCode_Clicked(object sender, EventArgs e)
{
Expand All @@ -50,7 +52,6 @@ async void btnStartCode_Clicked(object sender, EventArgs e)
{
await DisplayAlert("error", $"A fatal error was incountered while running your code\nException details:\n\tException type: {exc.GetType().ToString()}\n\terror message from interpreter:{exc.Message}.", "OK");
}
//await DisplayAlert("information", $"the code you were about to run is:\n{edCode.Text}", "OK");
}

private void btnReset_Clicked(object sender, EventArgs e)
Expand Down
6 changes: 3 additions & 3 deletions autoaccess/autoaccess/scriptables/tts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ public class tts
{
public async void speak(params object[] messages)
{
for(int i=0;i<messages.Length;i++)
foreach(var message in messages)
{
if (i == null)
if (message == null)
{
await TextToSpeech.SpeakAsync("null value");
return;
}
await TextToSpeech.SpeakAsync(messages[i].ToString());
await TextToSpeech.SpeakAsync(message.ToString());
}
}//func
}//class
Expand Down

0 comments on commit 51ac440

Please sign in to comment.