Jump to content

Template:Wn/si/evalx

From Wikimedia Incubator

( )

භාවිතය

[edit source]

This template evaluates an expression sequence using Module:Wn/si/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,

{{Wn/si/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}}.

{{Wn/si/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:Wn/si/Wikilisp, may be specified by non-blank template parameter test-eval.

Internals

[edit source]

When Module:Wn/si/Wikilisp is #invoked directly, rather than through an intermediary template such as {{Wn/si/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.

මේවාත් බලන්න

[edit source]