public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _) { TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>(); this.lua_extructor = lua_extructor; try { // Create metatable lua.CreateTable(); lua.PushManagedFunction(this.eq_func); lua.SetField(-2, "__eq"); // Create first table to compare lua.CreateTable(); lua.PushNumber(1); lua.SetField(-2, "A"); lua.Push(-2); lua.SetMetaTable(-2); // Create second table to compare lua.CreateTable(); lua.PushNumber(2); lua.SetField(-2, "A"); lua.Push(-3); lua.SetMetaTable(-2); // Get compare results bool equal_result = lua.Equal(-1, -2); bool raw_equal_result = lua.RawEqual(-1, -2); lua.Pop(3); if (!equal_result) { throw new EqualityTestException("ILua.Equal returned false but must return true"); } if (raw_equal_result) { throw new EqualityTestException("ILua.RawEqual returned true but must return false"); } taskCompletion.TrySetResult(true); } catch (Exception e) { taskCompletion.TrySetException(new Exception[] { e }); } return(taskCompletion.Task); }
public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _) { this.lua_extructor = lua_extructor; try { lua.CreateTable(); lua.CreateTable(); lua.PushManagedFunction(MetaToStringDelegate); lua.SetField(-2, "__tostring"); lua.SetMetaTable(-2); lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); lua.GetField(-1, "tostring"); lua.Push(-3); lua.MCall(1, 1); string get_val = lua.GetString(-1); lua.Pop(2); if (get_val != to_str_msg) { throw new CreateMetaTableException("Recieved string is incorrect"); } taskCompletion.TrySetResult(true); } catch (Exception e) { taskCompletion.TrySetException(new Exception[] { e }); } return(taskCompletion.Task); }
public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _) { TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>(); try { this.lua_extructor = lua_extructor; // Create new type this.type_id = lua.CreateMetaTable("SetTableAndRawSetTestType"); lua.PushManagedFunction(this.newIndexImpl); lua.SetField(-2, "__newindex"); lua.Pop(1); // Create test table lua.CreateTable(); lua.PushString(random1); lua.SetField(-2, "Val"); lua.PushMetaTable(this.type_id); lua.SetMetaTable(-2); // Test SetTable lua.PushString("Val"); lua.PushString(random1 + random1); lua.SetTable(-3); lua.GetField(-1, "Val"); string received_string = lua.GetString(-1); lua.Pop(1); if (received_string != random1 + random1) { throw new Exception("SetTable didn't set a value for an existing key"); } lua.PushString("ArbitraryKey"); lua.PushString("ArbitraryString"); lua.SetTable(-3); lua.GetField(-1, "ArbitraryKey"); int received_type = lua.GetType(-1); lua.Pop(1); if (received_type != (int)TYPES.NIL) { throw new Exception("SetTable ignored overriden __newindex"); } lua.PushString("Val2"); lua.PushString(random2); lua.RawSet(-3); lua.GetField(-1, "Val2"); string received_string2 = lua.GetString(-1); lua.Pop(1); if (received_string2 != random2) { throw new Exception("RawSet didn't set a value to a key"); } lua.Pop(1); lua.PushMetaTable(type_id); lua.PushNil(); lua.SetField(-2, "__newindex"); lua.Pop(1); taskCompletion.TrySetResult(true); } catch (Exception e) { taskCompletion.TrySetException(new Exception[] { e }); } return(taskCompletion.Task); }
public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _) { TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>(); try { this.lua_extructor = lua_extructor; this.NewTypeId = lua.CreateMetaTable("TestType1"); lua.PushManagedFunction(this.ToStringImpl); lua.SetField(-2, "__tostring"); lua.Pop(1); //Create new table to test newly created metatable lua.CreateTable(); lua.PushMetaTable(this.NewTypeId); lua.SetMetaTable(-2); /* * if(!lua.IsType(-1, this.NewTypeId)) * { * throw new Exception("Received type id is invalid"); * } * * string received_type_name = lua.GetTypeName(lua.GetType(-1)); * * if(received_type_name != "TestType1") * { * throw new Exception("Received type name is invalid"); * } */ lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); lua.GetField(-1, "tostring"); lua.Push(-3); lua.MCall(1, 1); if (lua.GetString(-1) != this.RandomString) { throw new Exception("Metatable method __tostring returned incorrect string"); } lua.Pop(3); lua.PushMetaTable(NewTypeId); lua.PushNil(); lua.SetField(-2, "__tostring"); lua.Pop(1); taskCompletion.TrySetResult(true); } catch (Exception e) { taskCompletion.TrySetException(new Exception[] { e }); } return(taskCompletion.Task); }
public Task <bool> Start(ILua lua, GetILuaFromLuaStatePointer lua_extructor, ModuleAssemblyLoadContext _) { TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>(); try { this.lua_extructor = lua_extructor; // Create new metatable and populate it this.TypeId = lua.CreateMetaTable("GetTableAndRawGetMetaTable"); lua.PushManagedFunction(this.indexDelegate); lua.SetField(-2, "__index"); lua.Pop(1); // Create a test table lua.CreateTable(); lua.PushString(this.RandomString2); lua.SetField(-2, "TestVal"); lua.PushMetaTable(this.TypeId); lua.SetMetaTable(-2); // Test GetTable lua.PushString("TestVal"); lua.GetTable(-2); string receivedString1 = lua.GetString(-1); if (receivedString1 != this.RandomString2) { throw new Exception("GetTable returned invalid string on existing key"); } lua.Pop(1); lua.PushString("ArbitraryString"); lua.GetTable(-2); string receivedString11 = lua.GetString(-1); if (receivedString11 != this.RandomString1) { throw new Exception("GetTable returned invalid string on non-existing key"); } lua.Pop(1); // Test RawGet lua.PushString("TestVal"); lua.RawGet(-2); string receivedString2 = lua.GetString(-1); if (receivedString2 != this.RandomString2) { throw new Exception("RawGet returned invalid string on existing key"); } lua.Pop(1); lua.PushString("ArbitraryString"); lua.RawGet(-2); int received_type = lua.GetType(-1); if (received_type != (int)TYPES.NIL) { throw new Exception("RawGet didn't return NIL on non-existing key"); } lua.Pop(1); lua.Pop(lua.Top()); lua.PushMetaTable(TypeId); lua.PushNil(); lua.SetField(-2, "__index"); lua.Pop(1); taskCompletion.TrySetResult(true); } catch (Exception e) { taskCompletion.TrySetException(new Exception[] { e }); } return(taskCompletion.Task); }