Шаблон:Evalx/doc
This is a documentation subpage for Шаблон:Evalx (see that page for the шаблон itself). It contains usage information, categories and other content that is not part of the original шаблон page. |
This шаблон is used on over 10,000 pages. Changes to this шаблон may cause some server load, and mistakes will be visible on many pages. Please carefully test any edits before making them, and avoid making unnecessary edits. |
Usage
This template evaluates an expression sequence using Module:Wikilisp. Pass the expression sequence as the first unnamed template parameter; all parameters to the template are also passed to the the module. For example,
- {{evalx|(get-substring (get-arg 2) 2 3)|abcd}}
would expand to
- bc
Here's a nontrivial example, made to work in concert with dialog verb edit. It modifies the entire content of a wiki page (provided through template parameter SUBJECT-CONTENT
) to submit the article for review on Wikinews, by removing calls to templates {{develop}} and {{tasks}} and adding a call at the top of the page to template {{review}}.
{{evalx|(define s (get-arg 2)) (define t (filter (parse s) call? (\x (member? (ucfirst (trim (get-substring s (nth (get-parts x) 1)))) (list "Dialog/submit" "Develop" "Developing" "Development" "Draft" "Tasks"))))) (set-substring s (+ (list (list 1 0)) t) (+ (list "{{(*}}{{(*}}review{{*)}}{{*)}}") (map (\x "") t))) |{{{SUBJECT-CONTENT|}}}}}
A different module, to use instead of Module:Wikilisp, may be specified by non-blank template parameter test-eval
.
Internals
When Module:Wikilisp is #invoke
d directly, rather than through an intermediary template such as {{evalx}}, the module point of entry is Lua function rep
, and the invocation parameters are accessible through Wikilisp functions get-arg
and get-arg-expr
. However, the intermediary template cannot explicitly pass its arbitrary template parameters to the invocation since it doesn't know their names in advance. To compensate, an alternative point of entry is provided through Lua function trep
, that feeds get-arg
and get-arg-expr
the parameters to the intermediary template instead of the parameters to #invoke
.
See also
- Module:Wikilisp for documentation of the expression language.