-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c20c768
commit 38042a1
Showing
33 changed files
with
546 additions
and
197 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using MoonSharp.Interpreter; | ||
using System; | ||
using System.ComponentModel; | ||
using System.Xml.Serialization; | ||
using UnityEngine; | ||
|
||
public abstract partial class Emitter : IXmlSerializable, IEmitter, INotifyPropertyChanged | ||
{ | ||
public class Action | ||
{ | ||
ActionType type; | ||
string name; | ||
string content; | ||
Closure closure; | ||
|
||
public enum ActionType { FunctionName, Inline, None, Closure }; | ||
|
||
|
||
public Action(Emitter emitter, string eventName, string type, string content) | ||
{ | ||
this.content = content; | ||
if(content == "") | ||
{ | ||
Debug.LogWarning("Empty or Invalid Action field."); | ||
this.type = ActionType.None; | ||
return; | ||
} | ||
switch(type) | ||
{ | ||
case "script": | ||
this.type = ActionType.FunctionName; | ||
break; | ||
default: | ||
this.type = ActionType.Inline; | ||
name = emitter.id + "_" + eventName; | ||
//Debug.Log(String.Format("New inline action {0}", name)); | ||
LUA.ScriptLoader.DoString(emitter.Category(), name + " = " + content); | ||
return; | ||
} | ||
} | ||
|
||
public Action(Closure closure) | ||
{ | ||
this.closure = closure; | ||
this.type = ActionType.Closure; | ||
} | ||
|
||
public DynValue Call(Emitter emitter, object[] args) | ||
{ | ||
switch (type) | ||
{ | ||
case ActionType.FunctionName: | ||
return LUA.ScriptLoader.Call(emitter.Category(), content, args); | ||
case ActionType.Inline: | ||
return LUA.ScriptLoader.Call(emitter.Category(), name, args); | ||
case ActionType.Closure: | ||
try | ||
{ | ||
return closure.Call(args); | ||
} | ||
catch (ScriptRuntimeException e) | ||
{ | ||
Debug.LogError("Script exception: " + e.DecoratedMessage); | ||
return null; | ||
} | ||
catch (ArgumentException e) | ||
{ | ||
Debug.LogError("Script exception while running call to action: " + e.Message); | ||
return null; | ||
} | ||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Oops, something went wrong.