[go: up one dir, main page]

File: lua2c.lua

package info (click to toggle)
tome 2.3.11-ah-2
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 18,976 kB
  • ctags: 12,278
  • sloc: ansic: 145,042; sh: 212; makefile: 70
file content (29 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- lua2c.lua
-- embed lua code into C source
-- celetecgraf.puc-rio.br
-- dez 2000

function embed (code)

 -- clean Lua code
 local s = clean(code)
 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('  lua_dobuffer(tolua_S,(char*)B,sizeof(B),"'..fn..': embedded Lua code");')
 output(' } /* end of embedded lua code */\n\n')
end