| 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 |
|
| 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 |
| 25 |
end |
| 26 |
|
| 27 |
function doit () |
| 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 |
| 37 |
|
| 38 |
-- parse table with extra paramters |
| 39 |
parse_extra() |
| 40 |
|
| 41 |
-- do this after setting the package name |
| 42 |
if flags['L'] then |
| 43 |
dofile(flags['L']) |
| 44 |
end |
| 45 |
|
| 46 |
-- add cppstring |
| 47 |
if not flags['S'] then |
| 48 |
_basic['string'] = 'cppstring' |
| 49 |
_basic['std::string'] = 'cppstring' |
| 50 |
_basic_ctype.cppstring = 'const char*' |
| 51 |
end |
| 52 |
|
| 53 |
-- proccess package |
| 54 |
local p = Package(flags.n,flags.f) |
| 55 |
|
| 56 |
if flags.p then |
| 57 |
return -- only parse |
| 58 |
end |
| 59 |
|
| 60 |
if flags.o then |
| 61 |
local st,msg = writeto(flags.o) |
| 62 |
if not st then |
| 63 |
error('#'..msg) |
| 64 |
end |
| 65 |
end |
| 66 |
|
| 67 |
p:decltype() |
| 68 |
if flags.P then |
| 69 |
p:print() |
| 70 |
else |
| 71 |
push(p) |
| 72 |
pre_output_hook(p) |
| 73 |
pop() |
| 74 |
p:preamble() |
| 75 |
p:supcode() |
| 76 |
push(p) |
| 77 |
pre_register_hook(p) |
| 78 |
pop() |
| 79 |
p:register() |
| 80 |
push(p) |
| 81 |
post_output_hook(p) |
| 82 |
pop() |
| 83 |
end |
| 84 |
|
| 85 |
if flags.o then |
| 86 |
writeto() |
| 87 |
end |
| 88 |
|
| 89 |
-- write header file |
| 90 |
if not flags.P then |
| 91 |
if flags.H then |
| 92 |
local st,msg = writeto(flags.H) |
| 93 |
if not st then |
| 94 |
error('#'..msg) |
| 95 |
end |
| 96 |
p:header() |
| 97 |
writeto() |
| 98 |
end |
| 99 |
end |
| 100 |
end |
| 101 |
|