开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 2 Fork 4

logbug/lua2c

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
贡献代码
同步代码
对比差异 通过 Pull Request 同步
同步更新到分支
通过 Pull Request 同步
将会在向当前分支创建一个 Pull
Request,合入后将完成同步
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT
lua2c - converts Lua 5.1 source code to C code.
== Description ==
This utility converts a given Lua source file into an equivalent C
source file written in terms of Lua C API calls. At least, this works
for a large subset of the Lua language (see limitations below).
The compiler is written entirely in Lua, and no build/install is
needed. This project reuses Metalua's gg/mlp parser to convert Lua
source to a Metalua-style [1] AST over which the compiler then
operates. lua2c does not require Metalua itself though since gg/mlp
is bundled in the distribution and is written in pure Lua.
== Usage ==
Example usage:
 lua lua2c.lua test/bisect.lua
which generates a C file to standard output.
You may also use the shell script "clua" to compile Lua->C->machine
code and execute all in one step. However, you may need to edit the
variables in the file to match your system since this utility invokes
the C compiler.
 ./clua test/bisect.lua
lua2c can even compile itself! (Note: the -c option compiles only
without running.)
 ./clua -c lua2c.lua # compile lua2c binary
 ./lua2c examples-lua/bisect.lua # test
== Related Work ==
 * luac2c - This related effort by Hisham Muhammad [2] converts Lua
 bytecodes to C source, whereas this project converts Lua
 source to C source. luac2c runs into a few similar
 limitations as given below. luac2c has remained experimental but
 superseded Luiz Henrique De Figueiredo's very basic but similarly
 named lua2c for Lua 4.0 [3].
 * luagen++ [4] uses C++ expression templates to translate
 Lua-like C++ statements to C API calls. Some of the code
 generation structure is actually fairly similar to lua2c.
 * Python Pyrex [5] does something similar in Python but has the
 added goal of lowering the boundary between C and Python
 code. Something like that could be done with lua2c,
 especially since lua2c uses the extensible gg parser.
 * Clue by David Given [6] does the opposite: convert C source
 to Lua source.
 * luac + BinToCee allow compilation of Lua source to bytecodes
 and/or embedding in a C file.
== Potential Uses ==
I think this project not only is theoretically nice to have but
has a number of potential uses:
 * Provide another approach of compiling Lua to machine code
 (rather than luac + bin2c).
 * Streamline the interface between C and Lua code and allow
 efficient access to C datatypes from Lua (see Pyrex above).
 * Compile Lua to optimized C. For example, by statically
 determining that certain variables are used in a restricted
 way (e.g. by decorating the Lua source file with pragmas or
 determining this implicitly by inference), certain code
 constructs might be simplified to use plain C rather that
 the Lua C API. This could allow certain Lua code written
 with sufficient care to run at native speeds. Since it compiles
 to C, it will even work on CPUs where LuaJIT is not available.
== Limitations / Status ==
WARNING: This code passes much of the Lua 5.1 test suite [7] and can
compile itself, but the code is new and there can still be errors.
In particular, a few language features (e.g. coroutines) are not
implemented. See comments in lua2c.lua for details. Please report
bugs/patches on the wiki.
lua2c does not currently support coroutines, functions that normally
reject C functions (e.g. setfenv), and possibly tail call
optimizations. Not all of these have the exact analogue in C.
Coroutines might not ever be supported. However, some solutions might
be explored [8][9], including possibly generating code that maintains
the coroutine context in Lua tables.
Closures and upvalues are implemented, but creating and accessing
upvalues is somewhat slow due to the implementation (see implementation
notes below) and hopefully can be improved.
Once the code is more complete/robust, more attention can be given to
optimizing the code generation. Performance was 25%-75% of regular
Lua when running a few tests [11], but hopefully future optimizations
will improve that.
== Lua 5.2 Notes ==
Note: LuaFiveTwo (as of 5.2.0-work4) deprecates getfenv and setfenv,
which eliminates one of the limitations above. LuaFiveTwo has new lua_arith
and lua_compare C API function, which eliminate the need for lua2c to
reimplement these functions. LuaFiveTwo also has new lua_yieldk, lua_callk,
and lua_pcallk functions for coroutines and might help to implement
coroutines in lua2c. 
== Project Page ==
The project page is currently http://lua-users.org/wiki/LuaToCee .
== Download ==
 * Latest development source (recommended): http://github.com/davidm/lua2c/ .
 From here you can browse the source, download a tar/zip snapshot, or
 checkout with git by running "{{git clone
 git://github.com/davidm/lua2c.git}}".
 * Last release distribution: (see Project Page above)
== Licensing ==
(c) 2008 David Manura. Licensed under the same terms as Lua (MIT
license). See included LICENSE file for full licensing details.
Please post any patches/improvements.
== References ==
 * [1] Metalua AST - http://metalua.luaforge.net/manual006.html#toc17
 * [2] luac2c (previously named luatoc) - LuaList:2006-07/msg00144.html
 * [3] LHF's lua2c for Lua 4.0 - LuaList:2002-01/msg00296.html
 * [4] luagen++ - LuaGenPlusPlus
 * [5] Pyrex - http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
 * [6] Clue - http://cluecc.sourceforge.net/
 * [7] Lua 5.1 test suite -
 http://www.inf.puc-rio.br/~roberto/lua/lua5.1-tests.tar.gz
 * [8] Wikipedia:Coroutine - Implementations for C
 http://en.wikipedia.org/wiki/Coroutine#Implementations_for_C
 * [9] Coco - http://luajit.org/coco.html Coco -
 True C coroutine semantics (used in LuaJIT)
 * [10] BinToCee - http://lua-users.org/wiki/BinToCee
 * [11] The Computer Language Benchmarks Game
 http://shootout.alioth.debian.org/gp4/lua.php
 * http://lua-users.org/wiki/LuaImplementations -
 other source translators and Lua reimplementations
lua2c Copyright (c) 2008 David Manura lua2c is available under the MIT licence. Significant parts of the compiler borrow code from other projects, all released under the MIT license: - Lua <http://www.lua.org> - Kein-Hong Man's Yueliang <http://luaforge.net/projects/yueliang> - Metalua <http://metalua.luaforge.net> MIT License =========== Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. >>>>> Metalua Copyright (c) 2006-2997 Fabien Fleutot <metalua@gmail.com> Metalua is available under the MIT licence. Significant parts of the compiler borrow code from other projects, all released under the MIT license: - Lua <http://www.lua.org> - Kein-Hong Man's Yueliang <http://luaforge.net/projects/yueliang> - Tomás Guisasola's Lua Rings <http://www.keplerproject.org/rings> - Ben Sunshine-Hill's Pluto <http://freshmeat.net/projects/pluto> - Thomas Reuben's Bitlib <http://luaforge.net/projects/bitlib> MIT License =========== Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. >>>>> Yueliang License ---------------- Yueliang is licensed under the terms of the MIT license reproduced below. This means that Yueliang is free software and can be used for both academic and commercial purposes at absolutely no cost. Yueliang is based on Lua 5 code. See COPYRIGHT_Lua5 (Lua 5.0.3) and COPYRIGHT_Lua51 (Lua 5.1.3) for Lua 5 license information. For details and rationale, see http://www.lua.org/license.html . =============================================================================== Yueliang Copyright (C) 2005-2008 Kein-Hong Man <khman@users.sf.net> Lua 5.0.3 Copyright (C) 2003-2006 Tecgraf, PUC-Rio. Lua 5.1.3 Copyright (C) 1994-2008 Lua.org, PUC-Rio. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =============================================================================== (end of COPYRIGHT) >>>>> Lua License ----------- Lua is licensed under the terms of the MIT license reproduced below. This means that Lua is free software and can be used for both academic and commercial purposes at absolutely no cost. For details and rationale, see http://www.lua.org/license.html . =============================================================================== Copyright (C) 1994-2008 Lua.org, PUC-Rio. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =============================================================================== (end of COPYRIGHT)
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

lua源代码转C语言源代码
暂无标签
README
MIT
使用 MIT 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/logbug/lua2c.git
git@gitee.com:logbug/lua2c.git
logbug
lua2c
lua2c
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /