Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 17, 2008, 8:59:48 PM (16 years ago)
Author:
rgrieder
Message:

Merged revisions 1875-2278 of the buildsystem branch to buildsystem2.

Location:
code/branches/buildsystem2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/buildsystem2

  • code/branches/buildsystem2/src/tolua/lua/code.lua

    r2087 r2509  
    1919--   text = text code
    2020classCode = {
    21  text = '',
     21    text = '',
    2222}
    2323classCode.__index = classCode
     
    2626-- register code
    2727function classCode:register (pre)
    28  pre = pre or ''
    29  -- clean Lua code
    30  local s = clean(self.text)
    31  if not s then
    32   --print(self.text)
    33   error("parser error in embedded code")
    34  end
     28    pre = pre or ''
     29    -- clean Lua code
     30    local s = clean(self.text)
     31    if not s then
     32        --print(self.text)
     33        error("parser error in embedded code")
     34    end
    3535
    36  -- get first line
    37  local _, _, first_line=string.find(self.text, "^([^\n\r]*)")
    38  if string.find(first_line, "^%s*%-%-") then
    39         if string.find(first_line, "^%-%-##") then
    40                 first_line = string.gsub(first_line, "^%-%-##", "")
    41                 if flags['C'] then
    42                         s = string.gsub(s, "^%-%-##[^\n\r]*\n", "")
    43                 end
    44         end
    45  else
    46         first_line = ""
    47  end
     36    -- get first line
     37    local _, _, first_line=string.find(self.text, "^([^\n\r]*)")
     38    if string.find(first_line, "^%s*%-%-") then
     39        if string.find(first_line, "^%-%-##") then
     40            first_line = string.gsub(first_line, "^%-%-##", "")
     41            if flags['C'] then
     42                s = string.gsub(s, "^%-%-##[^\n\r]*\n", "")
     43            end
     44        end
     45    else
     46        first_line = ""
     47    end
    4848
    49  -- convert to C
    50  output('\n'..pre..'{ /* begin embedded lua code */\n')
    51  output(pre..' int top = lua_gettop(tolua_S);')
    52  output(pre..' static unsigned char B[] = {\n   ')
    53  local t={n=0}
    54  local b = gsub(s,'(.)',function (c)
    55                          local e = ''
    56                          t.n=t.n+1 if t.n==15 then t.n=0 e='\n'..pre..'  ' end
    57                          return format('%3u,%s',strbyte(c),e)
    58                         end
    59                )
    60  output(b..strbyte(" "))
    61  output('\n'..pre..' };\n')
    62  if first_line and first_line ~= "" then
    63         output(pre..' tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua embedded: '..first_line..'");')
    64  else
    65         output(pre..' tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua: embedded Lua code '..code_n..'");')
    66  end
    67  output(pre..' lua_settop(tolua_S, top);')
    68  output(pre..'} /* end of embedded lua code */\n\n')
    69  code_n = code_n +1
     49    -- convert to C
     50    output('\n'..pre..'{ /* begin embedded lua code */\n')
     51    output(pre..' int top = lua_gettop(tolua_S);')
     52    output(pre..' static unsigned char B[] = {\n   ')
     53    local t={n=0}
     54    local b = gsub(s, '(.)',
     55        function (c)
     56            local e = ''
     57            t.n=t.n+1
     58            if t.n==15 then
     59             t.n=0 e='\n'..pre..'  '
     60            end
     61            return format('%3u,%s',strbyte(c),e)
     62        end
     63    )
     64    output(b..strbyte(" "))
     65    output('\n'..pre..' };\n')
     66    if first_line and first_line ~= "" then
     67        output(pre..' tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua embedded: '..first_line..'");')
     68    else
     69        output(pre..' tolua_dobuffer(tolua_S,(char*)B,sizeof(B),"tolua: embedded Lua code '..code_n..'");')
     70    end
     71    output(pre..' lua_settop(tolua_S, top);')
     72    output(pre..'} /* end of embedded lua code */\n\n')
     73    code_n = code_n +1
    7074end
    7175
     
    7377-- Print method
    7478function classCode:print (ident,close)
    75  print(ident.."Code{")
    76  print(ident.." text = [["..self.text.."]],")
    77  print(ident.."}"..close)
     79    print(ident.."Code{")
     80    print(ident.." text = [["..self.text.."]],")
     81    print(ident.."}"..close)
    7882end
    7983
     
    8185-- Internal constructor
    8286function _Code (t)
    83  setmetatable(t,classCode)
    84  append(t)
    85  return t
     87    setmetatable(t,classCode)
     88    append(t)
     89    return t
    8690end
    8791
     
    8993-- Expects a string representing the code text
    9094function Code (l)
    91  return _Code {
    92   text = l
    93  }
     95    return _Code {
     96        text = l
     97    }
    9498end
    9599
Note: See TracChangeset for help on using the changeset viewer.