如何将emscripten浏览器输入法从window.prompt改为更明智的东西? [英] How to change emscripten browser input method from window.prompt to something more sensible?

查看:134
本文介绍了如何将emscripten浏览器输入法从window.prompt改为更明智的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++函数,曾经从stdin中调用消耗输入。使用emscripten将此函数导出到javascript会导致调用window.prompt。

I have a C++ function which once called consumes input from stdin. Exporting this function to javascript using emscripten causes calls to window.prompt.

与浏览器提示交互是一件非常繁琐的工作。首先,您可以只粘贴一行。其次,表示EOF的唯一方法是按取消。最后但并非最不重要的唯一方法(在我的函数的情况下)让它停止要求用户输入window.prompt是通过选中复选框阻止更多提示弹出。

Interacting with browser prompt is really tedious task. First of all you can paste only one line at time. Secondly the only way to indicate EOF is by pressing 'cancel'. Last but not least the only way (in case of my function) to make it stop asking user for input by window.prompt is by checking the checkbox preventing more prompts to pop up.

对我来说,最好的输入法是阅读一些blob。我知道我可以破解library.js,但是我发现了一些问题:

For me the best input method would be reading some blob. I know I can hack library.js but I see some problems:


  1. 读取blob是异步的。

  2. 要读取blob,首先必须打开文件,用户必须先选择。

  3. 我真的不知道如何阻止我的函数永远读取这个blob - 有没有像window.prompt那样的复选框,我不确定如果它没有在window.prompt情况下(只检查复选框有帮助),发现EOF是否会停止它。

最好的解决方案是某种回调,但我希望看到来自更有经验的用户的sime提示。

The best solution would be some kind of callback but I would like to see sime hints from more experienced users.

推荐答案

根据我的理解,你可以尝试以下方法:

From what I understand you could try the following:


  1. 在Javascript中实现选择文件并通过Javascript访问它 Blob interface。

  2. Emscripten中分配一些内存

  1. Implement selecting a file in Javascript and access it via Javascript Blob interface.
  2. Allocate some memory in Emscripten

var buf = Module._malloc( blob.size );


  • 写下 Blob 从Javascript进入返回的内存位置。

  • Write the content of your Blob into the returned memory location from Javascript.

    Module.HEAPU8.set( new Uint8Array(blob), buf );
    


  • 将该内存位置传递给第二个 Emscripten 编译函数,然后处理文件内容和

  • Pass that memory location to a second Emscripten compiled function, which then processes the file content and

    解除分配已分配的内存。

    Deallocate allocated memory.

    Module._free( buf );
    


  • 最佳阅读 wiki

    这篇关于如何将emscripten浏览器输入法从window.prompt改为更明智的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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