Macros 2.0 expose runtime warn log function

0b529290aafd173717c5242a010fc077c607518d

Wolfsblvt <wolfsblvt@gmail.com>

2 files changed, +5 -2Ignore whitespace
public/scripts/macros/definitions/core-macros.js+2 -2
@@ -297,7 +297,7 @@ export function registerCoreMacros() {
297297 '{{roll::6}}',
298298 '{{roll::3d6+4}}',
299299 ],
300300 handler: ({ unnamedArgs: [formula], warn }) => {
301301 // If only digits were provided, treat it as `1dX`.
302302 if (/^\d+$/.test(formula)) {
303303 formula = `1d${formula}`;
@@ -305,7 +305,7 @@ export function registerCoreMacros() {
305305
306306 const isValid = droll.validate(formula);
307307 if (!isValid) {
308308 console.debugwarn(`Invalid roll formula: ${formula}`);
309309 return '';
310310 }
311311
public/scripts/macros/engine/MacroRegistry.js+3 -0
@@ -125,6 +125,8 @@ export const MacroValueType = Object.freeze({
125125 * Use when delayArgResolution is true. By default, preserves the caller's globalOffset so nested
126126 * macros like {{pick}} maintain deterministic position-based behavior. Pass offsetDelta to add
127127 * an additional offset for uniqueness (e.g., to differentiate between multiple resolve calls).
128+ * @property {(message: string, error?: any) => void} warn - Logs a runtime warning with automatic macro call context.
129+ * Use this to report issues in how the macro was invoked (e.g., invalid argument values, edge cases).
128130 */
129131
130132/**
@@ -375,6 +377,7 @@ class MacroRegistry {
375377 resolve: (text, { offsetDelta = 0 } = {}) => MacroEngine.evaluate(text, call.env, {
376378 contextOffset: call.globalOffset + offsetDelta,
377379 }),
380+ warn: (message, error = undefined) => logMacroRuntimeWarning({ message, call, def, error }),
378381 };
379382
380383 const result = def.handler(executionContext);