[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 | |
---|
[2229] | 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 () |
---|
[2229] | 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 | |
---|
[2229] | 38 | -- parse table with extra paramters |
---|
| 39 | parse_extra() |
---|
[1650] | 40 | |
---|
[2236] | 41 | -- get potential working directory |
---|
| 42 | if not flags.w then |
---|
| 43 | flags.w = '' |
---|
| 44 | end |
---|
| 45 | |
---|
[2229] | 46 | -- do this after setting the package name |
---|
[2236] | 47 | if flags.L then |
---|
| 48 | if string.sub(flags.L, 1, 1) == '/' or string.sub(flags.L, 1, 1) == '\\' then |
---|
| 49 | dofile(flags.L) |
---|
| 50 | else |
---|
| 51 | dofile(flags.w..'/'..flags.L) |
---|
| 52 | end |
---|
[2229] | 53 | end |
---|
[1650] | 54 | |
---|
[2229] | 55 | -- add cppstring |
---|
[2236] | 56 | if not flags.S then |
---|
[2229] | 57 | _basic['string'] = 'cppstring' |
---|
| 58 | _basic['std::string'] = 'cppstring' |
---|
| 59 | _basic_ctype.cppstring = 'const char*' |
---|
| 60 | end |
---|
[1650] | 61 | |
---|
[2229] | 62 | -- proccess package |
---|
[2252] | 63 | local file |
---|
| 64 | if flags.f then |
---|
[2236] | 65 | if string.sub(flags.f, 1, 1) == '/' or string.sub(flags.f, 1, 1) == '\\' 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 | |
---|
[2229] | 75 | if flags.p then |
---|
| 76 | return -- only parse |
---|
| 77 | end |
---|
[1650] | 78 | |
---|
[2229] | 79 | if flags.o then |
---|
[2252] | 80 | local file |
---|
[2236] | 81 | if string.sub(flags.o, 1, 1) == '/' or string.sub(flags.o, 1, 1) == '\\' then |
---|
| 82 | file = flags.o |
---|
| 83 | else |
---|
| 84 | file = flags.w..'/'..flags.o |
---|
| 85 | end |
---|
| 86 | local st,msg = writeto(file) |
---|
[2229] | 87 | if not st then |
---|
| 88 | error('#'..msg) |
---|
| 89 | end |
---|
| 90 | end |
---|
[1650] | 91 | |
---|
[2229] | 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 | |
---|
[2229] | 104 | if flags.o then |
---|
| 105 | writeto() |
---|
| 106 | end |
---|
[1650] | 107 | |
---|
[2229] | 108 | -- write header file |
---|
| 109 | if not flags.P then |
---|
| 110 | if flags.H then |
---|
[2252] | 111 | local file |
---|
[2236] | 112 | if string.sub(flags.H, 1, 1) == '/' or string.sub(flags.H, 1, 1) == '\\' then |
---|
| 113 | file = flags.H |
---|
| 114 | else |
---|
| 115 | file = flags.w..'/'..flags.H |
---|
| 116 | end |
---|
| 117 | local st,msg = writeto(file) |
---|
[2229] | 118 | if not st then |
---|
| 119 | error('#'..msg) |
---|
| 120 | end |
---|
| 121 | p:header() |
---|
| 122 | writeto() |
---|
| 123 | end |
---|
| 124 | end |
---|
[1650] | 125 | end |
---|
| 126 | |
---|