~ubuntu-branches/debian/sid/freeciv/sid

« back to all changes in this revision

Viewing changes to dependencies/tolua/basic.lua

  • Committer: Bazaar Package Importer
  • Author(s): Clint Adams, Karl Goetz, Clint Adams
  • Date: 2010-02-23 22:09:02 UTC
  • mfrom: (7.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100223220902-s3spqi1x4e190y0t
[ Karl Goetz ]
* Remove civserver files in /etc/ggzd/ (Closes: 523772, 517787)
* Adding ${misc:Depends} to all binary packages (lintian warnings)

[ Clint Adams ]
* New upstream version.
  - Drop data_dsc_use_bindir.diff (binary pathnames have changed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
 
3
 
 
4
 
_basic = {
5
 
 ['void'] = '',
6
 
 ['char'] = 'number',
7
 
 ['int'] = 'number',
8
 
 ['short'] = 'number',
9
 
 ['long'] = 'number',
10
 
 ['unsigned'] = 'number',
11
 
 ['float'] = 'number',
12
 
 ['double'] = 'number',
13
 
 ['_cstring'] = 'string',
14
 
 ['_userdata'] = 'userdata',
15
 
 ['char*'] = 'string',
16
 
 ['void*'] = 'userdata',
17
 
 ['bool'] = 'boolean',
18
 
 ['lua_State*'] = 'state',
19
 
 ['_lstate'] = 'state',
20
 
 ['lua_Object'] = 'value',
21
 
 ['lua_Function'] = 'function',
22
 
 ['LUA_VALUE'] = 'value',    -- for compatibility with tolua 4.0
23
 
}
24
 
 
25
 
_basic_ctype = {
26
 
 number = "lua_Number",
27
 
 string = "const char*",
28
 
 userdata = "void*",
29
 
 boolean = "bool",
30
 
 value = "int",
31
 
}
32
 
 
33
 
_usertype = {}
34
 
 
35
 
_collect = {}
36
 
 
37
 
 
38
 
_renaming = {}
39
 
function appendrenaming (s)
40
 
 local b,e,old,new = strfind(s,"%s*(.-)%s*@%s*(.-)%s*$")
41
 
        if not b then
42
 
         error("#Invalid renaming syntax; it should be of the form: pattern@pattern")
43
 
        end
44
 
        tinsert(_renaming,{old=old, new=new})
45
 
end
46
 
 
47
 
function applyrenaming (s)
48
 
        for i=1,getn(_renaming) do
49
 
         local m,n = gsub(s,_renaming[i].old,_renaming[i].new)
50
 
                if n ~= 0 then
51
 
                 return m
52
 
                end
53
 
        end
54
 
        return nil
55
 
end
56
 
 
57
 
function tolua_error (s,f)
58
 
 local out = _OUTPUT
59
 
 _OUTPUT = _STDERR
60
 
 if strsub(s,1,1) == '#' then
61
 
  write("\n** tolua: "..strsub(s,2)..".\n\n")
62
 
  if _curr_code then
63
 
   local _,_,s = strfind(_curr_code,"^%s*(.-\n)") -- extract first line
64
 
   if s==nil then s = _curr_code end
65
 
   s = gsub(s,"_userdata","void*") -- return with 'void*'
66
 
   s = gsub(s,"_cstring","char*")  -- return with 'char*'
67
 
   s = gsub(s,"_lstate","lua_State*")  -- return with 'lua_State*'
68
 
   write("Code being processed:\n"..s.."\n")
69
 
  end
70
 
 else
71
 
  print(debug.traceback("\n** tolua internal error: "..f..s..".\n\n"))
72
 
  return
73
 
 end
74
 
 _OUTPUT = out
75
 
end
76
 
 
77
 
function warning (msg)
78
 
 local out = _OUTPUT
79
 
 _OUTPUT = _STDERR
80
 
 write("\n** tolua warning: "..msg..".\n\n")
81
 
 _OUTPUT = out
82
 
end
83
 
 
84
 
function regtype (t)
85
 
 local ft = findtype(t)
86
 
        if isbasic(t) then
87
 
         return t
88
 
        end
89
 
 if not ft then
90
 
                return appendusertype(t)
91
 
 end
92
 
end
93
 
 
94
 
function typevar(type)
95
 
 if type == '' or type == 'void' then
96
 
  return type
97
 
 else
98
 
                local ft = findtype(type)
99
 
  if ft then
100
 
   return ft
101
 
  end
102
 
                _usertype[type] = type
103
 
                return type
104
 
        end
105
 
end
106
 
 
107
 
function isbasic (type)
108
 
 local t = gsub(type,'const ','')
109
 
 local m,t = applytypedef(t)
110
 
 local b = _basic[t]
111
 
 if b then
112
 
  return b,_basic_ctype[b]
113
 
 end
114
 
 return nil
115
 
end
116
 
 
117
 
function split (s,t)
118
 
 local l = {n=0}
119
 
 local f = function (s)
120
 
  l.n = l.n + 1
121
 
  l[l.n] = s
122
 
 end
123
 
 local p = "%s*(.-)%s*"..t.."%s*"
124
 
 s = gsub(s,"^%s+","")
125
 
 s = gsub(s,"%s+$","")
126
 
 s = gsub(s,p,f)
127
 
 l.n = l.n + 1
128
 
 l[l.n] = gsub(s,"(%s%s*)$","")
129
 
 return l
130
 
end
131
 
 
132
 
 
133
 
function concat (t,f,l)
134
 
 local s = ''
135
 
 local i=f
136
 
 while i<=l do
137
 
  s = s..t[i]
138
 
  i = i+1
139
 
  if i <= l then s = s..' ' end
140
 
 end
141
 
 return s
142
 
end
143
 
 
144
 
function concatparam (line, ...)
145
 
 local i=1
146
 
 while i<=arg.n do
147
 
  if _cont and not strfind(_cont,'[%(,"]') and 
148
 
     strfind(arg[i],"^[%a_~]") then 
149
 
            line = line .. ' ' 
150
 
  end
151
 
  line = line .. arg[i]
152
 
  if arg[i] ~= '' then
153
 
   _cont = strsub(arg[i],-1,-1)
154
 
  end
155
 
  i = i+1
156
 
 end
157
 
 if strfind(arg[arg.n],"[%/%)%;%{%}]$") then 
158
 
  _cont=nil line = line .. '\n'
159
 
 end
160
 
        return line
161
 
end
162
 
 
163
 
function output (...)
164
 
 local i=1
165
 
 while i<=arg.n do
166
 
  if _cont and not strfind(_cont,'[%(,"]') and 
167
 
     strfind(arg[i],"^[%a_~]") then 
168
 
            write(' ') 
169
 
  end
170
 
  write(arg[i])
171
 
  if arg[i] ~= '' then
172
 
   _cont = strsub(arg[i],-1,-1)
173
 
  end
174
 
  i = i+1
175
 
 end
176
 
 if strfind(arg[arg.n],"[%/%)%;%{%}]$") then 
177
 
  _cont=nil write('\n')
178
 
 end
179
 
end
180
 
 
181