📄 code.lua
字号:
-- tolua: code class-- Written by Waldemar Celes-- TeCGraf/PUC-Rio-- Jul 1999-- $Id: $-- This code is free software; you can redistribute it and/or modify it.-- The software provided hereunder is on an "as is" basis, and-- the author has no obligation to provide maintenance, support, updates,-- enhancements, or modifications. -- Code class-- Represents Lua code to be compiled and included-- in the initialization function.-- The following fields are stored:-- text = text codeclassCode = { text = '',}classCode.__index = classCodesetmetatable(classCode,classFeature)-- register codefunction classCode:register () -- clean Lua code local s = clean(self.text) if not s then error("parser error in embedded code") end -- convert to C output('\n { /* begin embedded lua code */\n') output(' static unsigned char B[] = {\n ') local t={n=0} local b = gsub(s,'(.)',function (c) local e = '' t.n=t.n+1 if t.n==15 then t.n=0 e='\n ' end return format('%3u,%s',strbyte(c),e) end ) output(b..strbyte(" ")) output('\n };\n') output(' luaL_loadbuffer(tolua_S,(char*)B,sizeof(B),"tolua: embedded Lua code") ||\n') output(' lua_pcall(tolua_S,0,LUA_MULTRET,0);') output(' } /* end of embedded lua code */\n\n')end -- Print methodfunction classCode:print (ident,close) print(ident.."Code{") print(ident.." text = [["..self.text.."]],") print(ident.."}"..close)end-- Internal constructorfunction _Code (t) setmetatable(t,classCode) append(t) return tend-- Constructor-- Expects a string representing the code textfunction Code (l) return _Code { text = l }end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -