-- lua2c.lua - Driver for lua2c - converts Lua 5.1 source to C code.---- STATUS:-- WARNING: This code passes much of the Lua 5.1 test suite,-- but there could still be errors. In particular, a few-- language features (e.g. coroutines) are not implemented.---- Unimplemented Lua language features:-- - deprecated old style vararg (arg) table inside vararg functions-- (LUA_COMPAT_VARARG)-- - debug.getinfo(f, 'n').name for C-based functions-- - setfenv does not permit C-based functions-- - how well do tail call optimizations work?-- - how to handle coroutines? (see README)-- Note: A few things (coroutines) might remain-- unimplemented--see README file file for details.---- Possible improvements:-- - Fix: large numerical literals can give gcc warnings such as-- 'warning: integer constant is too large for "long" type').-- Literal numbers are rendered as C integers literals (e.g. 123)-- rather than C double literals (eg. 123.0).-- - improved debug tracebacks on exceptions-- - See items marked FIX in below code.---- SOURCE:---- http://lua-users.org/wiki/LuaToCee---- (c) 2008 David Manura. Licensed in the same terms as Lua (MIT license).-- See included LICENSE file for full licensing details.-- Please post any patches/improvements.--local _G = _Glocal assert = _G.assertlocal error = _G.errorlocal io = _G.iolocal ipairs = _G.ipairslocal os = _G.oslocal package = _G.packagelocal require = _G.requirelocal string = _G.stringlocal table = _G.table-- package.path = './lib/?.lua;' .. package.path-- note: includes gg/mlp Lua parsing Libraries taken from Metalua.require "lexer"require "gg"require "mlp_lexer"require "mlp_misc"require "mlp_table"require "mlp_meta"require "mlp_expr"require "mlp_stat"require "mlp_ext"_G.mlc = {} -- make gg happylocal mlp = assert(_G.mlp)local A2C = require "lua2c.ast2cast"local C2S = require "lua2c.cast2string"local function NOTIMPL(s)error('FIX - NOT IMPLEMENTED: ' .. s, 2)endlocal function DEBUG(...)local ts = {...}for i,v in ipairs(ts) dots[i] = table.tostring(v,'nohash',60)endio.stderr:write(table.concat(ts, ' ') .. '\n')end-- Converts Lua source string to Lua AST (via mlp/gg)local function string_to_ast(src)local lx = mlp.lexer:newstream (src)local ast = mlp.chunk (lx)return astendlocal src_filename = ...if not src_filename thenio.stderr:write("usage: lua2c filename.lua\n")os.exit(1)endlocal src_file = assert(io.open (src_filename, 'r'))local src = src_file:read '*a'; src_file:close()src = src:gsub('^#[^\r\n]*', '') -- remove any shebanglocal ast = string_to_ast(src)local cast = A2C.ast_to_cast(src, ast)-- DEBUG(cast)io.stdout:write(C2S.cast_to_string(cast))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。