Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/SuperOrxoBros_HS18/src/external/tolua/lua/typedef.lua @ 12175

Last change on this file since 12175 was 12175, checked in by siramesh, 5 years ago

Super Orxo Bros (Sidharth Ramesh, Nisa Balta, Jeff Ren)

File size: 1.8 KB
Line 
1-- tolua: typedef class
2-- Written by Waldemar Celes
3-- TeCGraf/PUC-Rio
4-- Jul 1998
5-- $Id: $
6
7-- This code is free software; you can redistribute it and/or modify it.
8-- The software provided hereunder is on an "as is" basis, and
9-- the author has no obligation to provide maintenance, support, updates,
10-- enhancements, or modifications.
11
12
13
14-- Typedef class
15-- Represents a type synonym.
16-- The 'de facto' type replaces the typedef before the
17-- remaining code is parsed.
18-- The following fields are stored:
19--   utype = typedef name
20--   type = 'the facto' type
21--   mod = modifiers to the 'de facto' type
22classTypedef = {
23    utype = '',
24    mod = '',
25    type = ''
26}
27classTypedef.__index = classTypedef
28
29-- Print method
30function classTypedef:print (ident,close)
31    print(ident.."Typedef{")
32    print(ident.." utype = '"..self.utype.."',")
33    print(ident.." mod = '"..self.mod.."',")
34    print(ident.." type = '"..self.type.."',")
35    print(ident.."}"..close)
36end
37
38-- Return it's not a variable
39function classTypedef:isvariable ()
40    return false
41end
42
43-- Internal constructor
44function _Typedef (t)
45    setmetatable(t,classTypedef)
46    t.type = resolve_template_types(t.type)
47    appendtypedef(t)
48    return t
49end
50
51-- Constructor
52-- Expects one string representing the type definition.
53function Typedef (s)
54    if strfind(string.gsub(s, '%b<>', ''),'[%*&]') then
55        tolua_error("#invalid typedef: pointers (and references) are not supported")
56    end
57    local o = {mod = ''}
58    if string.find(s, "[<>]") then
59        _,_,o.type,o.utype = string.find(s, "^%s*([^<>]+%b<>[^%s]*)%s+(.-)$")
60    else
61        local t = split(gsub(s,"%s%s*"," ")," ")
62        o = {
63            utype = t[t.n],
64            type = t[t.n-1],
65            mod = concat(t,1,t.n-2),
66        }
67    end
68    return _Typedef(o)
69end
70
71
Note: See TracBrowser for help on using the repository browser.