【问题标题】:Is there a way to insert raw javascript in parenscript code?有没有办法在 parenscript 代码中插入原始 javascript?
【发布时间】:2015-08-05 13:28:41
【问题描述】:

以下代码将第三方生成的 javascript 作为需要进行评估的字符串插入。

(ps (let ((x (lisp (json:encode-json-alist-to-string
                 '((:a . 1) (:b . 2))))))))

"(function () {
   var x = '{\"a\":1,\"b\":2}';
    return null; })();"

有没有办法告诉 parenscript 插入不带引号的字符串?

【问题讨论】:

    标签: common-lisp parenscript


    【解决方案1】:

    将此添加到 parenscript 的非 cl.lisp 文件中:

    (define-expression-operator lisp-raw (lisp-form)
      `(ps-js:escape
        ,lisp-form))
    
    (defun lisp-raw (x) x)
    

    结果:

    (ps (let ((x (ps::lisp-raw (json:encode-json-alist-to-string
                     '((:a . 1) (:b . 2))))))))
    "(function () {
        var x = {\"a\":1,\"b\":2};
        return null;
    })();"
    

    【讨论】:

      猜你喜欢
      • 2021-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      • 1970-01-01
      • 2018-06-14
      • 2012-07-17
      相关资源
      最近更新 更多