Changeset 2664 for code/branches/buildsystem3/src/tolua/lua/compat.lua
- Timestamp:
- Feb 14, 2009, 10:53:45 PM (16 years ago)
- Location:
- code/branches/buildsystem3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/buildsystem3
- Property svn:ignore deleted
- Property svn:mergeinfo changed
-
code/branches/buildsystem3/src/tolua/lua/compat.lua
r2087 r2664 34 34 35 35 function do_ (f, err) 36 if not f then print(err); return end37 local a,b = pcall(f)38 if not a then print(b); return nil39 else return b or true40 end36 if not f then print(err); return end 37 local a,b = pcall(f) 38 if not a then print(b); return nil 39 else return b or true 40 end 41 41 end 42 42 … … 141 141 142 142 function flush (f) 143 if f then f:flush()144 else _OUTPUT:flush()145 end143 if f then f:flush() 144 else _OUTPUT:flush() 145 end 146 146 end 147 147 148 148 function readfrom (name) 149 if name == nil then150 local f, err, cod = io.close(_INPUT)151 _INPUT = io.stdin152 return f, err, cod153 else154 local f, err, cod = io.open(name, "r")155 _INPUT = f or _INPUT156 return f, err, cod157 end149 if name == nil then 150 local f, err, cod = io.close(_INPUT) 151 _INPUT = io.stdin 152 return f, err, cod 153 else 154 local f, err, cod = io.open(name, "r") 155 _INPUT = f or _INPUT 156 return f, err, cod 157 end 158 158 end 159 159 160 160 function writeto (name) 161 if name == nil then162 local f, err, cod = io.close(_OUTPUT)163 _OUTPUT = io.stdout164 return f, err, cod165 else166 local f, err, cod = io.open(name, "w")167 _OUTPUT = f or _OUTPUT168 return f, err, cod169 end161 if name == nil then 162 local f, err, cod = io.close(_OUTPUT) 163 _OUTPUT = io.stdout 164 return f, err, cod 165 else 166 local f, err, cod = io.open(name, "w") 167 _OUTPUT = f or _OUTPUT 168 return f, err, cod 169 end 170 170 end 171 171 172 172 function appendto (name) 173 local f, err, cod = io.open(name, "a")174 _OUTPUT = f or _OUTPUT175 return f, err, cod173 local f, err, cod = io.open(name, "a") 174 _OUTPUT = f or _OUTPUT 175 return f, err, cod 176 176 end 177 177 178 178 function read (...) 179 local f = _INPUT180 if rawtype(arg[1]) == 'userdata' then181 f = tab.remove(arg, 1)182 end183 return f:read(unpack(arg))179 local f = _INPUT 180 if rawtype(arg[1]) == 'userdata' then 181 f = tab.remove(arg, 1) 182 end 183 return f:read(unpack(arg)) 184 184 end 185 185 186 186 function write (...) 187 local f = _OUTPUT188 if rawtype(arg[1]) == 'userdata' then189 f = tab.remove(arg, 1)190 end191 return f:write(unpack(arg))187 local f = _OUTPUT 188 if rawtype(arg[1]) == 'userdata' then 189 f = tab.remove(arg, 1) 190 end 191 return f:write(unpack(arg)) 192 192 end 193 193
Note: See TracChangeset
for help on using the changeset viewer.