add new %begin directive for inserting code at top of wrapper file

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11133 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2009-02-20 07:52:24 +00:00
commit efa11dee52
31 changed files with 334 additions and 162 deletions

View file

@ -92,6 +92,7 @@ NEW LANGUAGE NOTE:END ************************************************/
class LUA:public Language {
private:
File *f_begin;
File *f_runtime;
File *f_header;
File *f_wrappers;
@ -132,6 +133,7 @@ public:
* --------------------------------------------------------------------- */
LUA() {
f_begin = 0;
f_runtime = 0;
f_header = 0;
f_wrappers = 0;
@ -213,11 +215,12 @@ public:
String *outfile = Getattr(n, "outfile");
/* Open the output file */
f_runtime = NewFile(outfile, "w", SWIG_output_files());
if (!f_runtime) {
f_begin = NewFile(outfile, "w", SWIG_output_files());
if (!f_begin) {
FileErrorDisplay(outfile);
SWIG_exit(EXIT_FAILURE);
}
f_runtime = NewString("");
f_init = NewString("");
f_header = NewString("");
f_wrappers = NewString("");
@ -226,6 +229,7 @@ public:
/* Register file targets with the SWIG file handler */
Swig_register_filebyname("header", f_header);
Swig_register_filebyname("wrapper", f_wrappers);
Swig_register_filebyname("begin", f_begin);
Swig_register_filebyname("runtime", f_runtime);
Swig_register_filebyname("init", f_init);
Swig_register_filebyname("initbeforefunc", f_initbeforefunc);
@ -249,8 +253,9 @@ public:
current=NO_CPP;
/* Standard stuff for the SWIG runtime section */
Swig_banner(f_runtime);
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGLUA\n");
// if (NoInclude) {
@ -293,13 +298,14 @@ public:
this basically combines several of the strings together
and then writes it all to a file
NEW LANGUAGE NOTE:END ************************************************/
Dump(f_header, f_runtime);
Dump(f_wrappers, f_runtime);
Dump(f_initbeforefunc, f_runtime);
Dump(f_runtime, f_begin);
Dump(f_header, f_begin);
Dump(f_wrappers, f_begin);
Dump(f_initbeforefunc, f_begin);
/* for the Lua code it needs to be properly excaped to be added into the C/C++ code */
EscapeCode(s_luacode);
Printf(f_runtime, "const char* SWIG_LUACODE=\n \"%s\";\n\n",s_luacode);
Wrapper_pretty_print(f_init, f_runtime);
Printf(f_begin, "const char* SWIG_LUACODE=\n \"%s\";\n\n",s_luacode);
Wrapper_pretty_print(f_init, f_begin);
/* Close all of the files */
Delete(s_luacode);
Delete(s_cmd_tab);
@ -309,8 +315,9 @@ public:
Delete(f_wrappers);
Delete(f_init);
Delete(f_initbeforefunc);
Close(f_runtime);
Close(f_begin);
Delete(f_runtime);
Delete(f_begin);
/* Done */
return SWIG_OK;