如何在Funscript中导出接口 [英] How are interfaces exported in Funscript

查看:69
本文介绍了如何在Funscript中导出接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有了Funscript示例。现在我正在尝试制作类似Funscript库的东西,它具有可以从javascript代码调用的函数(希望是类!)。但我看不到从Funscript生成的.js访问任何内容的方法。

I've got the Funscript examples working. Now I'm trying to make something like a Funscript library which has functions (and hopefully classes!) that can be called from javascript code. But I can't see a way of accessing anything from the .js generated from Funscript.

简而言之,我如何让Javascript调用Funscript?

In short, how do I get Javascript to call Funscript?

推荐答案

很抱歉, FunScript 是不是为这个用例而设计的。它旨在消耗脚本中各种来源的代码和数据,而不是将代码导出为库。

Sorry but FunScript is not designed for this use case. It is designed for consuming code and data from various sources in a script rather than for exporting code as a library.

您会注意到FunScript生成的代码非常难看。我们最近略有改进,但这些更改只能直接从 FunScript存储库中获取(在撰写本文时) )。在生成可以从其他基于JavaScript的语言中使用的JavaScript之前,还有很长的路要走。

You will notice the code FunScript generates is quite ugly. We have improved it slightly recently but these changes are only available directly from the FunScript repository (at the time of writing). There is still a long way to go before it generates JavaScript that is nice to consume from other JavaScript based languages.

改进代码生成不是高优先级的任务。项目现在。我们不想承诺以任何特定的样式/格式生成代码,同时我们正在积极地添加大量新功能。此外,很难将F#中的一些概念映射到可消耗和高性能的JavaScript中。例如:

Improving the code generation is not a high priority task for the project right now. We don't want to commit to generating code in any particular style/format whilst we are actively adding large bits of new functionality. Also, it is hard to map some concepts from F# into consumable and performant JavaScript. For example:


  • 通用类型,方法和函数

  • 通用类型约束(关于等式和比较)

  • 反思

为了说明一般情况,假设在F#中你有一个泛型函数,它使用比较约束来对泛型类型的实例数组进行排序。首先,将它与原始数字类型(如int)一起使用。其次,您将它与记录类型一起使用。如果为这两种情况生成相同的JavaScript代码,并且通过调用某些方法来实现比较,例如比较(...),则会导致对象的性能非常差数字案例。为了获得更好的性能,需要对生成的代码进行一些特化。这里可以内联映射到内置JavaScript类型(如数字和字符串)的F#类型的比较。这提供了更好的性能,但是,您现在拥有相同F#函数的多个JavaScript版本。没有一种明确的方式以易于使用的方式呈现这个生成的代码。

To illustrate the generic case, suppose in F# you have a generic function that makes use of a comparison constraint to sort an array of instances of the generic type. First, you use it with a primitive numeric type like int. Second, you use it with a record type. If the same JavaScript code is generated for both situations and the comparison is achieved by calling some method say Compare(...) on the objects this results in very poor performance for the numeric case. To achieve better performance, some specialisation of the generated code is needed. Here the comparison of F# types that map to built in JavaScript types (like number and string) can be inlined. This gives much better performance, however, you now have multiple JavaScript versions of the same F# function. There isn't a clear way to present this generated code in an easy to consume fashion.

总之,FunScript设计做了一些权衡,优先考虑支持泛型,性能和对代码生成等内容的反思。您可能希望查看WebSharper。它可能支持这个用例。

In summary, the FunScript design makes some trade offs that prioritise things like support for generics, performance and reflection over things like code generation. You may want to look at WebSharper instead. It may support this use case.

这篇关于如何在Funscript中导出接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆