Macros 2.0 expose runtime warn log function
| @@ -297,7 +297,7 @@ export function registerCoreMacros() { | ||
| 297 | 297 | '{{roll::6}}', |
| 298 | 298 | '{{roll::3d6+4}}', |
| 299 | 299 | ], |
| 300 | 300 | handler: ({ unnamedArgs: [formula], warn }) => { |
| 301 | 301 | // If only digits were provided, treat it as `1dX`. |
| 302 | 302 | if (/^\d+$/.test(formula)) { |
| 303 | 303 | formula = `1d${formula}`; |
| @@ -305,7 +305,7 @@ export function registerCoreMacros() { | ||
| 305 | 305 | |
| 306 | 306 | const isValid = droll.validate(formula); |
| 307 | 307 | if (!isValid) { |
| 308 | 308 | console.debugwarn(`Invalid roll formula: ${formula}`); |
| 309 | 309 | return ''; |
| 310 | 310 | } |
| 311 | 311 | |
| @@ -125,6 +125,8 @@ export const MacroValueType = Object.freeze({ | ||
| 125 | 125 | * Use when delayArgResolution is true. By default, preserves the caller's globalOffset so nested |
| 126 | 126 | * macros like {{pick}} maintain deterministic position-based behavior. Pass offsetDelta to add |
| 127 | 127 | * 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). | |
| 128 | 130 | */ |
| 129 | 131 | |
| 130 | 132 | /** |
| @@ -375,6 +377,7 @@ class MacroRegistry { | ||
| 375 | 377 | resolve: (text, { offsetDelta = 0 } = {}) => MacroEngine.evaluate(text, call.env, { |
| 376 | 378 | contextOffset: call.globalOffset + offsetDelta, |
| 377 | 379 | }), |
| 380 | + warn: (message, error = undefined) => logMacroRuntimeWarning({ message, call, def, error }), | |
| 378 | 381 | }; |
| 379 | 382 | |
| 380 | 383 | const result = def.handler(executionContext); |