Beispiel #1
0
 public void PushToLua(ILua lua)
 {
     lua.CreateTable();
     lua.PushVector(Coordinates);
     lua.SetField(-2, "Coordinates");
     lua.PushVector(FootPos);
     lua.SetField(-2, "FootPos");
 }
Beispiel #2
0
 public static void PushGlobalVector(ILua lua, string key, Vector3 value)
 {
     lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
     lua.GetField(-1, "CNode");
     lua.PushVector(value);
     lua.SetField(-2, key);
     lua.Pop();
 }
Beispiel #3
0
 public void PushToLua(ILua lua)
 {
     lua.CreateTable();
     lua.PushString(Name);
     lua.SetField(-2, "Name");
     lua.PushVector(NodeSize);
     lua.SetField(-2, "NodeSize");
 }
        int SpawnFunc(ILua lua)
        {
            try
            {
                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                lua.GetField(-1, "ents");
                lua.GetField(-1, "Create");
                lua.PushString("prop_physics");
                lua.MCall(1, 1);

                if (lua.GetType(-1) != (int)TYPES.ENTITY)
                {
                    throw new SpawnEntityException("ents.Create returned a value which type is not Entity");
                }

                lua.GetField(-1, "SetModel");
                lua.Push(-2);
                lua.PushString("models/props_c17/oildrum001.mdl");
                lua.MCall(2, 0);

                lua.GetField(-1, "SetPos");
                lua.Push(-2);
                lua.PushVector(new System.Numerics.Vector3(0));
                lua.MCall(2, 0);

                lua.GetField(-1, "Spawn");
                lua.Push(-2);
                lua.MCall(1, 0);

                lua.GetField(-1, "IsValid");
                lua.Push(-2);
                lua.MCall(1, 1);
                if (!lua.GetBool(-1))
                {
                    throw new SpawnEntityException("Entity is not valid");
                }

                lua.Pop(lua.Top());

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(0);
        }
Beispiel #5
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();

            try
            {
                Random rand = new Random();

                string field_id = Guid.NewGuid().ToString();

                float x = (float)rand.NextDouble() + rand.Next(-100, 101);
                float y = (float)rand.NextDouble() + rand.Next(-100, 101);
                float z = (float)rand.NextDouble() + rand.Next(-100, 101);

                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);

                lua.PushVector(new Vector3(x, y, z));
                lua.SetField(-2, field_id);

                lua.GetField(-1, field_id);
                Vector3 recieved_vec = lua.GetVector(-1);
                lua.Pop(2);

                if (recieved_vec != new Vector3(x, y, z))
                {
                    throw new PushVectorException(recieved_vec, new Vector3(x, y, z));
                }

                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }
Beispiel #6
0
        public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _)
        {
            try
            {
                Random rand = new Random();

                int    curr_type;
                string curr_name;

                lua.PushNumber(rand.NextDouble());
                curr_type = lua.GetType(-1);
                curr_name = lua.GetTypeName(curr_type);
                if (curr_type != (int)TYPES.NUMBER || curr_name != "number")
                {
                    throw new CheckTypeException("number");
                }
                lua.Pop(1);


                lua.PushString(Guid.NewGuid().ToString());
                curr_type = lua.GetType(-1);
                curr_name = lua.GetTypeName(curr_type);
                if (curr_type != (int)TYPES.STRING || curr_name != "string")
                {
                    throw new CheckTypeException("string");
                }
                lua.Pop(1);


                lua.PushBool(true);
                curr_type = lua.GetType(-1);
                curr_name = lua.GetTypeName(curr_type);
                if (curr_type != (int)TYPES.BOOL || curr_name != "bool")
                {
                    throw new CheckTypeException("bool");
                }
                lua.Pop(1);


                lua.PushNil();
                curr_type = lua.GetType(-1);
                curr_name = lua.GetTypeName(curr_type);
                if (curr_type != (int)TYPES.NIL || curr_name != "nil")
                {
                    throw new CheckTypeException("nil");
                }
                lua.Pop(1);


                lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
                curr_type = lua.GetType(-1);
                curr_name = lua.GetTypeName(curr_type);
                if (curr_type != (int)TYPES.TABLE || curr_name != "table")
                {
                    throw new CheckTypeException("table");
                }
                lua.Pop(1);


                lua.PushVector(new Vector3((float)rand.NextDouble()));
                curr_type = lua.GetType(-1);
                curr_name = lua.GetTypeName(curr_type);
                if (curr_type != (int)TYPES.Vector || curr_name != "vector")
                {
                    throw new CheckTypeException("vector");
                }
                lua.Pop(1);


                lua.PushAngle(new Vector3((float)rand.NextDouble()));
                curr_type = lua.GetType(-1);
                curr_name = lua.GetTypeName(curr_type);
                if (curr_type != (int)TYPES.ANGLE || curr_name != "angle")
                {
                    throw new CheckTypeException("angle");
                }
                lua.Pop(1);


                lua.PushManagedFunction(this.test_func);
                curr_type = lua.GetType(-1);
                curr_name = lua.GetTypeName(curr_type);
                if (curr_type != (int)TYPES.FUNCTION || curr_name != "function")
                {
                    throw new CheckTypeException("function");
                }
                lua.Pop(1);



                taskCompletion.TrySetResult(true);
            }
            catch (Exception e)
            {
                taskCompletion.TrySetException(new Exception[] { e });
            }

            return(taskCompletion.Task);
        }