コード例 #1
0
 public ScriptFunction(Script scriptRef, DynValue function, LuaFuncType type)
 {
     this.ScriptRef     = scriptRef;
     LuaFunc            = function;
     IsCoroutine        = !type.HasFlag(LuaFuncType.Function);
     AutoResetCoroutine = type.HasFlag(LuaFuncType.AutoCoroutine);
     Coroutine          = IsCoroutine ? scriptRef.CreateCoroutine(LuaFunc) : null;
     FuncType           = type;
 }
コード例 #2
0
 /// <summary>
 /// Creates a script hook from a reference script and a string containing a function
 /// </summary>
 /// <param name="scriptRef">A MoonSharp script to associate this <see cref="ScriptFunction"/> with</param>
 /// <param name="singleFunctionString">an unnamed function string<para/>Example: "function() print('test') end"</param>
 /// <param name="coroutine">is it a coroutine?</param>
 /// <param name="autoreset">should the coroutine reset automatically?</param>
 public ScriptFunction(Script scriptRef, string singleFunctionString, bool coroutine = false, bool autoreset = true)
 {
     this.ScriptRef     = scriptRef;
     LuaFunc            = scriptRef.LoadFunction(singleFunctionString);
     IsCoroutine        = coroutine;
     AutoResetCoroutine = autoreset;
     Coroutine          = coroutine ? scriptRef.CreateCoroutine(LuaFunc) : null;
     FuncType           = StandardHelpers.GetLuaFuncType(coroutine, autoreset);
 }
コード例 #3
0
 public ScriptFunction(Script scriptRef, DynValue function, bool coroutine = false, bool autoreset = true)
 {
     this.ScriptRef     = scriptRef;
     LuaFunc            = function;
     IsCoroutine        = coroutine;
     AutoResetCoroutine = autoreset;
     Coroutine          = coroutine ? scriptRef.CreateCoroutine(LuaFunc) : null;
     FuncType           = StandardHelpers.GetLuaFuncType(coroutine, autoreset);
 }
コード例 #4
0
 public ScriptFunction(Script scriptRef, string singleFunctionString)
 {
     this.ScriptRef     = scriptRef;
     LuaFunc            = scriptRef.LoadFunction(singleFunctionString);
     IsCoroutine        = false;
     AutoResetCoroutine = false;
     Coroutine          = null;
     FuncType           = StandardHelpers.GetLuaFuncType(false, false);
 }
コード例 #5
0
 /// <summary>
 /// Clone the other scripthook. Also creates a new coroutine with the same settings as the original
 /// </summary>
 /// <param name="other"></param>
 public ScriptFunction(ScriptFunction other)
 {
     this.ScriptRef     = other.ScriptRef;
     LuaFunc            = other.LuaFunc;
     IsCoroutine        = other.IsCoroutine;
     AutoResetCoroutine = other.AutoResetCoroutine;
     Coroutine          = IsCoroutine ? ScriptRef.CreateCoroutine(LuaFunc) : null;
     if (IsCoroutine)
     {
         Coroutine.Coroutine.AutoYieldCounter = other.Coroutine.Coroutine.AutoYieldCounter;
     }
     FuncType = other.FuncType;
 }
コード例 #6
0
        public LuaFuncStandard(string path, LuaFuncType type, bool required = true)
        {
            Path     = path;
            FuncType = type;
            Required = required;

            if (FuncType.HasFlag(LuaFuncType.AllowAny) && (((int)FuncType & 0b0111) < 1))
            {
                throw new ArgumentException("Type must also contain FuncType.Function, FuncType.SingleUseCoroutine, or FuncType.AutoCoroutine", "type");
            }

            if (FuncType.HasFlag(LuaFuncType.AllowAnyCoroutine) && (((int)FuncType & 0b0110) < 1))
            {
                throw new ArgumentException("Type must also contain FuncType.SingleUseCoroutine or FuncType.AutoCoroutine", "type");
            }
        }
コード例 #7
0
        /// <summary>
        /// Creates a <see cref="LuaFuncStandard"/>
        /// </summary>
        /// <param name="path">The global function name. Paths not yet implemented, but this can be bypassed by registering the function manually</param>
        /// <param name="isCoroutine">Is it a coroutine</param>
        /// <param name="autoResetCoroutine">Should the coroutine automatically reset? (create a new coroutine when it dies?)</param>
        /// <param name="required">Does this function have to be implemented?</param>
        public LuaFuncStandard(string path, bool isCoroutine = false, bool autoResetCoroutine = false, bool required = true)
        {
            Path     = path;
            Required = required;

            if (isCoroutine)
            {
                if (autoResetCoroutine)
                {
                    FuncType = LuaFuncType.AutoCoroutine;
                }
                else
                {
                    FuncType = LuaFuncType.SingleUseCoroutine;
                }
            }
            else
            {
                FuncType = LuaFuncType.Function;
            }
        }