TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

A lightweight (~5000 LOC) Python interpreter for game engines

106 点作者 vitaut超过 2 年前

21 条评论

versteegen超过 2 年前
I&#x27;ve been waiting a long time for MicroPython to become usable as an embedded script interpreter -- it can&#x27;t be run asynchronously [1] so scripts can&#x27;t do waits (aside from that, MicroPython is amazingly full-featured). CPython can&#x27;t either, which is why the Stackless Python fork was created, which is used in games such as EVE Online. But that&#x27;s far too heavy for my tastes.<p>So I was hoping that PocketPy could do that, but after looking around I can&#x27;t find any suggestion it&#x27;s possible, and the API looks very sparse. I&#x27;m very happy to see a new Python interpreter built for embedding, but I can&#x27;t use it. Maybe it can be added easily enough. Keep it up!<p>If you want to see a scripting language designed from the ground up for embedding, Lua and Squirrel IMO have the most complete APIs (though not the most efficient or easy to use) [2][3], and LuaJIT has even better lua&lt;-&gt;C bridging. I&#x27;ve looked at the APIs of many other small scripting languages, and haven&#x27;t found any others that can do everything that these can.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;micropython&#x2F;micropython&#x2F;issues&#x2F;3619">https:&#x2F;&#x2F;github.com&#x2F;micropython&#x2F;micropython&#x2F;issues&#x2F;3619</a><p>[2] In particular <a href="https:&#x2F;&#x2F;www.lua.org&#x2F;manual&#x2F;5.4&#x2F;manual.html#4.5" rel="nofollow">https:&#x2F;&#x2F;www.lua.org&#x2F;manual&#x2F;5.4&#x2F;manual.html#4.5</a><p>[3] <a href="http:&#x2F;&#x2F;squirrel-lang.org&#x2F;squirreldoc&#x2F;reference&#x2F;embedding_squirrel.html" rel="nofollow">http:&#x2F;&#x2F;squirrel-lang.org&#x2F;squirreldoc&#x2F;reference&#x2F;embedding_squ...</a>
评论 #34706856 未加载
评论 #34706268 未加载
314超过 2 年前
Nice idea, as python is much easier to write code for than lua so should fit game scripting well.<p>But, the examples are not the kinds of things that I would care about before trying to put this into a game engine. It needs a different set of examples.<p>* How hard is it to call into a C function from a hook in the py code?<p>* How hard is it to wrap &#x2F; unwrap values from their py representation to C?<p>If you want people to <i>embed</i> the interpreter into an engine then show that it is clean&#x2F;easy to do the embedding, rather than showing that the interpreter can execute code. I would assume that it executes python, but need to know how well it embeds.
评论 #34706444 未加载
评论 #34707786 未加载
评论 #34708349 未加载
vkazanov超过 2 年前
So is this a clean reimplementation? Given how small this is it probably is.<p>Which means this is not Python but a language that is syntax-compatible (&quot;Python-like&quot;). To prove compatibility something like a (very) extensive set of compatibility tests would have to be written and mentioned in the README. Otherwise it&#x27;s a minefield of subtle semantic differences.
评论 #34707130 未加载
bragr超过 2 年前
What&#x27;s the performance like compared to Lua? Since Lua is the standard here, this feels like nonstarter unless the performance is similar, even with the friendlier python syntax.
评论 #34704092 未加载
评论 #34706912 未加载
voxelghost超过 2 年前
If the author comes around, first of all congratulations on what seems like a really cool project. Second, I am curious as to whether the lack of &#x27;star unpack&#x27; is due to any real blocker, or more of a &#x27;not done yet&#x27;&#x2F;&#x27;not prioritized&#x27;?
benob超过 2 年前
How does this compare to tinypy? [1] <a href="http:&#x2F;&#x2F;www.tinypy.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.tinypy.org&#x2F;</a>
评论 #34706622 未加载
jsjohnst超过 2 年前
How is this on the homepage twice with no comments and less than 10 votes?
评论 #34706659 未加载
ZoomZoomZoom超过 2 年前
There&#x27;s not only the question of why use this over Lua, but why use this over many compile-to-lua languages, providing a great range of syntax and typing features.
评论 #34706896 未加载
peterbmarks超过 2 年前
I wonder how it compares with MicroPython?
评论 #34704869 未加载
simonw超过 2 年前
The demo is fun to play with: <a href="https:&#x2F;&#x2F;blueloveth.github.io&#x2F;pocketpy&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blueloveth.github.io&#x2F;pocketpy&#x2F;</a><p>It uses <a href="https:&#x2F;&#x2F;blueloveth.github.io&#x2F;pocketpy&#x2F;lib&#x2F;pocketpy.wasm" rel="nofollow">https:&#x2F;&#x2F;blueloveth.github.io&#x2F;pocketpy&#x2F;lib&#x2F;pocketpy.wasm</a> which is 766.66 kB - transferred compressed as 240.72 kB
评论 #34704831 未加载
avinassh超过 2 年前
Wow, this is excellent! I love the fact that it is just in 5K lines. I have a few questions!<p>1. What were your motivations for building this?<p>2. Did you eval any similar projects before writing this one?<p>3. Can this be compiled to WASM and used in the browser? edit: I see that it already supports WASM!<p>4. I didn&#x27;t see this on the README, but does it support IO (either disk or network)?<p>5. I noticed you linked to byterun. Does this also implement a VM similar to Python? Can I run the bytecode produced from CPython in the pocketpy VM? If so, are there any reasons for that? I thought writing an independent implementation would be faster&#x2F;easier than a compatible one.<p>6. Any plans on adding type annotations?
BlackLotus89超过 2 年前
Hmm duplicate of <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=34702386" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=34702386</a> maybe I should text @dang to merge...
winter_blue超过 2 年前
Hmm, wish this had been built as a PocketPy -&gt; LLVM compiler. While the compiler might not have been lightweight, the final emitted binaries would have been superfast.
评论 #34704625 未加载
评论 #34705748 未加载
评论 #34704858 未加载
评论 #34705176 未加载
forgotpwd16超过 2 年前
*interpreter for a small Python subset<p>Should be expected from the size of codebase but should also be clearly mentioned. And this isn&#x27;t about just lacking Python&#x27;s modules. Plain language features are also not there. For example reversing a string with &quot;abcd&quot;[-1::-1] doesn&#x27;t work. Now there&#x27;s a features list on README, but not sure whether this is meant to be the comprehensive list this subset has or just a TODO.
dividedbyzero超过 2 年前
This is neat! I assume this is Python 3?<p>Still looking for a replacement for the excellent Jython project [1] on the JVM, which has been fantastic for adding scripting to Java&#x2F;Scala based projects, but sadly stuck on Python 2.7. I wonder if this could be bolted onto or run inside a JVM somehow (perhaps the WebAssembly version?)<p>1: <a href="https:&#x2F;&#x2F;www.jython.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.jython.org&#x2F;</a>
评论 #34708001 未加载
awelxtr超过 2 年前
I thought that &quot;weight&quot; generally referred to less resource usage (RAM primarly, cpu second) and loc weren&#x27;t part of those resources.<p>Was I wrong?
评论 #34705855 未加载
评论 #34705519 未加载
nattaylor超过 2 年前
I&#x27;d like to give the WASM build a try
brunovcosta超过 2 年前
Great project!!<p>I was trying to build my own python interpreter to my project and this saved me a lot of work!<p><i>super nice-to-have ask:</i> could you replace the is_prime test on the README from range(2,x) to range(2,int(math.sqrt(x)))?
blondin超过 2 年前
impressive work! i suppose it implements a subset and not the full language? would be nice to see some benchmarks. everyone claims super fast nowadays. i have no doubt though, since it&#x27;s cpp.
评论 #34703836 未加载
评论 #34703871 未加载
qikInNdOutReply超过 2 年前
Why not lua though?
pipeline_peak超过 2 年前
an i for an i is an i in range