-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from ethanmoffat/bot_script_objects
EOBot: Add support for objects in script files. Define $account, $character, and $mapstate built-in variables.
- Loading branch information
Showing
18 changed files
with
387 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ public enum BotTokenType | |
MinusOperator, | ||
MultiplyOperator, | ||
DivideOperator, | ||
Dot, | ||
NewLine, | ||
Error, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using EOBot.Interpreter.States; | ||
using EOBot.Interpreter.Variables; | ||
using System.Collections.Generic; | ||
|
||
namespace EOBot.Interpreter.Extensions | ||
{ | ||
public static class SymbolTableExtensions | ||
{ | ||
|
||
public static (EvalResult Result, string Reason, IVariable Variable) GetVariable(this Dictionary<string, (bool, IIdentifiable Identifiable)> symbols, string identifier, int? arrayIndex = null) | ||
{ | ||
if (!symbols.ContainsKey(identifier)) | ||
symbols[identifier] = (false, UndefinedVariable.Instance); | ||
|
||
var variableValue = symbols[identifier].Identifiable as IVariable; | ||
if (variableValue == null) | ||
{ | ||
return (EvalResult.Failed, $"Identifier {identifier} is not a variable", null); | ||
} | ||
|
||
if (arrayIndex != null) | ||
{ | ||
var arrayVariable = variableValue as ArrayVariable; | ||
|
||
if (arrayVariable == null) | ||
{ | ||
return (EvalResult.Failed, $"Identifier {identifier} is not an array", null); | ||
} | ||
|
||
if (arrayVariable.Value.Count <= arrayIndex.Value) | ||
{ | ||
return (EvalResult.Failed, $"Index {arrayIndex.Value} is out of range of the array {identifier} (size {arrayVariable.Value.Count})", null); | ||
} | ||
|
||
variableValue = arrayVariable.Value[arrayIndex.Value]; | ||
} | ||
|
||
return (EvalResult.Ok, string.Empty, variableValue); | ||
} | ||
|
||
public static (EvalResult Result, string Reason, T Variable) GetVariable<T>(this Dictionary<string, (bool, IIdentifiable)> symbols, string identifier, int? arrayIndex = null) | ||
where T : class, IVariable | ||
{ | ||
var getResult = GetVariable(symbols, identifier, arrayIndex); | ||
|
||
if (getResult.Result != EvalResult.Ok) | ||
return (getResult.Result, getResult.Reason, null); | ||
|
||
var variable = getResult.Variable as T; | ||
if (variable == null) | ||
return (EvalResult.Failed, $"Identifier {identifier} is not a {typeof(T).Name}", null); | ||
|
||
return (EvalResult.Ok, string.Empty, variable); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.