⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 code.lua

📁 tolua++是一个对lua进行封装调用的工具
💻 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.-- globalcode_n = 1-- 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 (pre) pre = pre or '' -- clean Lua code local s = clean(self.text) if not s then  --print(self.text)  error("parser error in embedded code") end -- get first line local _, _, first_line=string.find(self.text, "^([^\n\r]*)") if string.find(first_line, "^%s*%-%-") then	 if string.find(first_line, "^%-%-##") then		first_line = string.gsub(first_line, "^%-%-##", "")		if flags['C'] then			s = string.gsub(s, "^%-%-##[^\n\r]*\n", "")		end	 end else 	first_line = "" end -- convert to C output('\n'..pre..'{ /* begin embedded lua code */\n') output(pre..' int top = lua_gettop(tolua_S);') output(pre..' 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'..pre..'  ' end                         return format('%3u,%s',strbyte(c),e)                        end               ) output(b..strbyte(" ")) output('\n'..pre..' };\n') if first_line and first_line ~= "" then 	output(pre..' tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua embedded: '..first_line..'");') else 	output(pre..' tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua: embedded Lua code '..code_n..'");') end output(pre..' lua_settop(tolua_S, top);') output(pre..'} /* end of embedded lua code */\n\n') code_n = code_n +1end-- 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 + -