You can escape the 1st formatting via %%
, as in the 1st example below.
Alternatively (depending on the context/complexity of your code), you can "trick" the above snippet by passing b
as a formatting string itself, so that you satisfy the 1st for required fields, but leave there ready the resulting string as a formatting one:
1) escape the 1st formatting via %%
local formatString = 'Name: %(a)s Age: %%(b)s';
local v = formatString % { a: 'a' };
{
asd: v % { b: '1' },
}
2) using same formatting string
local formatString = 'Name: %(a)s Age: %(b)s';
local v = formatString % { a: 'a', b: '%(b)s' };
{
asd: v % { b: '1' },
}
3) using a variable for "lazy" (late) formatting
Same as 2)
but kinda generalized:
local lazyEvalVar = 'someVar'; // `b` in the above example
local lazyEvalString = '%(someVar)s';
local formatString = 'Name: %(a)s Age: ' + lazyEvalString;
local v = formatString % { a: 'a', [lazyEvalVar]: lazyEvalString };
{
asd: v % { [lazyEvalVar]: '1' },
}