[1650] | 1 | -- Generate binding code |
---|
| 2 | -- Written by Waldemar Celes |
---|
| 3 | -- TeCGraf/PUC-Rio |
---|
| 4 | -- Jul 1998 |
---|
| 5 | -- Last update: Apr 2003 |
---|
| 6 | -- $Id: $ |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | -- This code is free software; you can redistribute it and/or modify it. |
---|
| 10 | -- The software provided hereunder is on an "as is" basis, and |
---|
| 11 | -- the author has no obligation to provide maintenance, support, updates, |
---|
| 12 | -- enhancements, or modifications. |
---|
| 13 | |
---|
| 14 | function parse_extra() |
---|
| 15 | |
---|
[2664] | 16 | for k,v in ipairs(_extra_parameters or {}) do |
---|
| 17 | |
---|
| 18 | local b,e,name,value = string.find(v, "^([^=])=(.*)$") |
---|
| 19 | if b then |
---|
| 20 | _extra_parameters[name] = value |
---|
| 21 | else |
---|
| 22 | _extra_parameters[v] = true |
---|
| 23 | end |
---|
| 24 | end |
---|
[1650] | 25 | end |
---|
| 26 | |
---|
| 27 | function doit () |
---|
[2664] | 28 | -- define package name, if not provided |
---|
| 29 | if not flags.n then |
---|
| 30 | if flags.f then |
---|
| 31 | flags.n = gsub(flags.f,"%..*$","") |
---|
| 32 | _,_,flags.n = string.find(flags.n, "([^/\\]*)$") |
---|
| 33 | else |
---|
| 34 | error("#no package name nor input file provided") |
---|
| 35 | end |
---|
| 36 | end |
---|
[1650] | 37 | |
---|
[2664] | 38 | -- parse table with extra paramters |
---|
| 39 | parse_extra() |
---|
[1650] | 40 | |
---|
[2664] | 41 | -- get potential working directory |
---|
| 42 | if not flags.w then |
---|
| 43 | flags.w = '' |
---|
| 44 | end |
---|
[1650] | 45 | |
---|
[2664] | 46 | -- do this after setting the package name |
---|
| 47 | if flags.L then |
---|
| 48 | if string.sub(flags.L, 1, 1) == '/' or string.sub(flags.L, 1, 1) == '\\' or (string.len(flags.L) > 1 and string.sub(flags.L, 2, 2) == ':') then |
---|
| 49 | dofile(flags.L) |
---|
| 50 | else |
---|
| 51 | dofile(flags.w..'/'..flags.L) |
---|
| 52 | end |
---|
| 53 | end |
---|
[1650] | 54 | |
---|
[2664] | 55 | -- add cppstring |
---|
| 56 | if not flags.S then |
---|
| 57 | _basic['string'] = 'cppstring' |
---|
| 58 | _basic['std::string'] = 'cppstring' |
---|
| 59 | _basic_ctype.cppstring = 'const char*' |
---|
| 60 | end |
---|
[1650] | 61 | |
---|
[2664] | 62 | -- proccess package |
---|
| 63 | local file |
---|
| 64 | if flags.f then |
---|
| 65 | if string.sub(flags.f, 1, 1) == '/' or string.sub(flags.f, 1, 1) == '\\' or (string.len(flags.f) > 1 and string.sub(flags.f, 2, 2) == ':') then |
---|
| 66 | file = flags.f |
---|
| 67 | else |
---|
| 68 | file = flags.w..'/'..flags.f |
---|
| 69 | end |
---|
| 70 | else |
---|
| 71 | file = flags.f |
---|
| 72 | end |
---|
| 73 | local p = Package(flags.n, file) |
---|
[1650] | 74 | |
---|
[2664] | 75 | if flags.p then |
---|
| 76 | return -- only parse |
---|
| 77 | end |
---|
[1650] | 78 | |
---|
[2664] | 79 | if flags.o then |
---|
| 80 | local file |
---|
| 81 | if string.sub(flags.o, 1, 1) == '/' or string.sub(flags.o, 1, 1) == '\\' or (string.len(flags.o) > 1 and string.sub(flags.o, 2, 2) == ':') then |
---|
| 82 | file = flags.o |
---|
| 83 | else |
---|
| 84 | file = flags.w..'/'..flags.o |
---|
| 85 | end |
---|
| 86 | local st,msg = writeto(file) |
---|
| 87 | if not st then |
---|
| 88 | error('#'..msg) |
---|
| 89 | end |
---|
| 90 | end |
---|
[1650] | 91 | |
---|
[2664] | 92 | p:decltype() |
---|
| 93 | if flags.P then |
---|
| 94 | p:print() |
---|
| 95 | else |
---|
| 96 | p:preamble() |
---|
| 97 | p:supcode() |
---|
| 98 | p:register() |
---|
| 99 | push(p) |
---|
| 100 | post_output_hook(p) |
---|
| 101 | pop() |
---|
| 102 | end |
---|
[1650] | 103 | |
---|
[2664] | 104 | if flags.o then |
---|
| 105 | writeto() |
---|
| 106 | end |
---|
| 107 | |
---|
| 108 | -- write header file |
---|
| 109 | if not flags.P then |
---|
| 110 | if flags.H then |
---|
| 111 | local file |
---|
| 112 | if string.sub(flags.H, 1, 1) == '/' or string.sub(flags.H, 1, 1) == '\\' or (string.len(flags.H) > 1 and string.sub(flags.H, 2, 2) == ':') then |
---|
| 113 | file = flags.H |
---|
| 114 | else |
---|
| 115 | file = flags.w..'/'..flags.H |
---|
| 116 | end |
---|
| 117 | local st,msg = writeto(file) |
---|
| 118 | if not st then |
---|
| 119 | error('#'..msg) |
---|
| 120 | end |
---|
| 121 | p:header() |
---|
| 122 | writeto() |
---|
| 123 | end |
---|
| 124 | end |
---|
[1650] | 125 | end |
---|
| 126 | |
---|