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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Show HN: Luastatic – Build an executable from a Lua program

44 点作者 ers35超过 9 年前

7 条评论

camperman超过 9 年前
You can do this in Luajit with the following trick:<p><pre><code> for f in *.lua; do luajit -b $f `basename $f .lua`.o done ar rcus libmylib.a *.o gcc -o myexe main-stub.c -I&#x2F;usr&#x2F;local&#x2F;include&#x2F;luajit-2.0 -L&#x2F;usr&#x2F;local&#x2F;lib -lluajit-5.1 -Wl,--whole-archive libmylib.a -Wl,--no-whole-archive -Wl,-E </code></pre> Where main-stub.c looks like this:<p><pre><code> #include &lt;lua.h&gt; #include &lt;lauxlib.h&gt; #include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; int main(void) { int status, result, i; lua_State *L; L = luaL_newstate(); luaL_openlibs(L); &#x2F;* load your lua entry point here *&#x2F; status = luaL_loadfile(L, &quot;mainluafile.lua&quot;); if (status) { fprintf(stderr, &quot;Couldn&#x27;t load file: %s\n&quot;, lua_tostring(L, -1)); exit(1); } result = lua_pcall(L, 0, LUA_MULTRET, 0); if (result) { fprintf(stderr, &quot;Failed to run script: %s\n&quot;, lua_tostring(L, -1)); exit(1); } lua_close(L); return 0; } </code></pre> The executables produced are very small because you dynamically link to Luajit and statically link to your own Lua code. I have a full media scheduler running at 100 sites which is only 40k. And it runs like a demon on ARM too.
评论 #10452177 未加载
larme超过 9 年前
For multiple lua files, you can first bundle them into a single lua file using squish.[0]<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;LuaDist&#x2F;squish" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;LuaDist&#x2F;squish</a>
fasteo超过 9 年前
Also check:<p>Bundle [1], using LuaJIT<p>Luvi [2], which is also able to generate a single file executable and you can include static resources.<p>[1] <a href="https:&#x2F;&#x2F;luapower.com&#x2F;bundle" rel="nofollow">https:&#x2F;&#x2F;luapower.com&#x2F;bundle</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;luvit&#x2F;luvi" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;luvit&#x2F;luvi</a>
unmole超过 9 年前
Similar project for Python: <a href="http:&#x2F;&#x2F;www.pyinstaller.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.pyinstaller.org&#x2F;</a> Works with multiple source files and supports widely used Python modules out of the box.
motiejus超过 9 年前
Pretty good size: 214K (on amd64 Linux):<p><pre><code> $ ls -lhd hello -rwxr-xr-x 1 admin admin 214K Oct 26 09:53 hello $ ldd hello linux-vdso.so.1 (0x00007fff5f5ff000) libm.so.6 =&gt; &#x2F;lib&#x2F;x86_64-linux-gnu&#x2F;libm.so.6 (0x00007f10611e7000) libdl.so.2 =&gt; &#x2F;lib&#x2F;x86_64-linux-gnu&#x2F;libdl.so.2 (0x00007f1060fe3000) libc.so.6 =&gt; &#x2F;lib&#x2F;x86_64-linux-gnu&#x2F;libc.so.6 (0x00007f1060c39000) &#x2F;lib64&#x2F;ld-linux-x86-64.so.2 (0x00007f10614f6000) </code></pre> (edit: formatting)
hbbio超过 9 年前
This is an interesting project, thanks for sharing.<p>Did you explore the possibility to use LuaJIT instead? The ability to do this and also integrate with Terra <a href="http:&#x2F;&#x2F;terralang.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;terralang.org&#x2F;</a> would create a great project!
评论 #10450417 未加载
评论 #10450543 未加载
ifoundthetao超过 9 年前
Ha! I remember you from the G-Wan forum days (:<p>I&#x27;m so excited to see you&#x27;re still active!