在浏览器中运行 C [英] Running C in A Browser

查看:25
本文介绍了在浏览器中运行 C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了几天时间研究这个看似简单的问题:是否有可能在浏览器中运行 C 代码?基本上,我在 Appengine 中设置了一个站点,该站点需要运行(一组受信任的)用户提供的一些 C 代码并运行它,并将代码的输出返回给用户.我有两个选择:要么需要在浏览器中完全运行代码,要么找到某种方法让 Python 在没有任何系统调用的情况下运行此 C 代码.

I've spent days of research over the seemingly simple question: is it possible to run C code in a browser at all? Basically, I have a site set up in Appengine that needs to run some C code supplied by (a group of trusted) users and run it, and return the output of the code back to the user. I have two options from here: I either need to completely run the code in the browser, or find some way to have Python run this C code without any system calls.

我看到了对我的问题的不同回答.我见过 Emscripten 之类的解决方案,但这不起作用,因为我需要在浏览器中生成 LLVM 代码(我无法在 AppEngine 中运行编译器.)我尝试了各种技术,包括从 codepad.org 上的输出页面抓取,但我将产生的输出如此之高,以至于我无法使用像 codepad.org 这样的服务,因为它们会修剪输出(我的输出约为 20,000 行,每行约 60 个字符,已修剪由于超时而通过键盘).我最后的手段是制作我自己的服务器,该服务器可以满足来自我的 Appengine 站点的请求,但这似乎有点极端.

I've seen mixed responses to my question. I've seen solutions like Emscripten, but that doesn't work because I need the LLVM code to be produced in the browser (I cannot run compilers in AppEngine.) I've tried various techniques, including scraping from the output page on codepad.org, but the output I will produce is so high that I cannot use services like codepad.org because they trim the output (my output will be ~20,000 lines of about 60 characters each, which is trimmed by codepad due to a timeout). My last resort is to make my own server that can serve my requests from my Appengine site, but that seems a little extreme.

我的用户提供的代码将是非常简单的 C.他们的代码没有调用 I/O 或系统操作.不幸的是,我可能不能简单地在他们的代码中使用查找/替换操作将其转换为 Javascript,因为他们可能使用多维数组甚至类等结构.

The code supplied by my users will be very simple C. There are no I/O or system operations called by their code. Unfortunately, I probably cannot simply use a find/replace operation in their code to translate it to Javascript, because they may use structures like multidimensional arrays or maybe even classes.

我可以将我的用户限制在一个跨平台浏览器上,例如铬或火狐.谁能帮我找到这个问题的解决方案?我已经困惑了好几天了.

I'm fine with limiting my users to one cross-platform browser, e.g. Chrome or Firefox. Can anyone help me find a solution to this question? I've been baffled for days.

推荐答案

老问题,但对于那些在 2018 年来到这里的人来说,Web Assembly 值得一看.

Old question but for those that land in here in 2018 it would be worth looking at Web Assembly.

这篇关于在浏览器中运行 C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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