Repository navigation
Function default non-primitive values #397
Description
Hello @yanghuan
There are troubles with exported metadata with default values mentioned here.
However, further tests showed another major issue with the whole default value transpilation.
There is another major problem with the transpiled default value according to the compiled source code.
I have attached examples of C# source and target Lua code that is completely incorrect.
Valid C#
protected Paladin(unit u) : base(u, new HeroStats()
{
baseDMG = 1,
baseARM = 0,
baseMR = 123,
baseHP = 0,
baseMP = 0,
baseMS = 0
}, new HeroStats()
{
baseDMG = 23,
baseARM = 13,
baseMR = 22,
baseAttackCooldown = 2.15f,
baseHP = 500,
baseMP = 120,
baseMS = 300f,
regenHP = 1,
incomingHealing = 0.05f,
})Invalid Lua.
__ctor__ = function (this, u)
local default = NoxRavenUnitAgents.HeroStats()
default:setbaseDMG(1)
default:setbaseARM(0)
default:setbaseMR(123)
default:setbaseHP(0)
default:setbaseMP(0)
default:setbaseMS(0)
local default = NoxRavenUnitAgents.HeroStats()
default:setbaseDMG(23)
default:setbaseARM(13)
default:setbaseMR(22)
default:setbaseAttackCooldown(2.15)
default:setbaseHP(500)
default:setbaseMP(120)
default:setbaseMS(300)
default:setregenHP(1)
default:setincomingHealing(0.05)
System.base(this).__ctor__(this, u, default, default)
endNot only the default is parsed twice, which is already incorrect behaviour, default variable name is instantly reused by the compiler when transpiling multiple objects in the function. The behaviour occurs not only for ctor constructor.
Functions with predefined primitive values behave properly.
Valid C#
public Status ApplyStatus(NoxUnit source, NoxUnit target, int level, float duration, int initialStacks = 1, int bonusLevel = 0, float bonusDuration = 0, int bonusStacks = 1)
///.......
GhoulEnrage.ApplyStatus(evt.caller, evt.caller, 1, 2, 1, 0, 0, 0);Valid Lua
class.GhoulEnrage:ApplyStatus1(evt.caller, evt.caller, 1, 2, 1, 0, 0, 0)If I remove manually defined values in the function ApplyStatus to the following:
GhoulEnrage.ApplyStatus(evt.caller, evt.caller, 1, 2);Produces valid Lua using predefined primitive values in the ApplyStatus definition.
class.GhoulEnrage:ApplyStatus1(evt.caller, evt.caller, 1, 2, 1, 0, 0, 1)This is the expected behaviour which only occurs for primitive values.
Current workaround is to use no more than one non-primitive default type in function definition.
Activity
yanghuan commentedon Aug 1, 2022
thanks, but i can't reproduce this issue
will got
it is no problem, Whether I missed anything ?
Drake53 commentedon Aug 20, 2022
@AzuStar Can you check if you still have this issue with v1.7.17? Maybe it was already fixed but my fork wasn't up-to-date.