Add feature:constasvar to guile module

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9255 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
John Lenz 2006-08-19 23:32:56 +00:00
commit e59a47f6b1
4 changed files with 50 additions and 4 deletions

View file

@ -1,6 +1,10 @@
Version 1.3.30 (in progress)
============================
08/19/2006: wuzzeb (John Lenz)
[Guile] Add feature:constasvar to export constants as variables instead of functions
that return the constant value.
08/11/2006: wsfulton
[Java] DetachCurrentThread calls have been added so that natively created threads
no longer prevent the JVM from exiting. Bug reported by Thomas Dudziak and

View file

@ -405,6 +405,13 @@ In <code><var>body</var></code>, the first result of
See also the "multivalue" example.
</p>
<p>Constants are exported as a function that returns the value. The
%feature("constasvar") can be applied to any constant, immutable variable, or enum.
Instead of exporting the constant as a function that must be called, the
constant will appear as a scheme variable. See
<a href="Customization.html#features">Features and the %feature directive</a>
for info on how to apply the %feature.</p>
<H2><a name="Guile_nn12"></a>19.6 Representation of pointers as smobs</H2>

4
README
View file

@ -89,6 +89,10 @@ Information about SWIG is also available in Japanese translation at
What's New?
===========
SWIG-1.3.30 summary:
- Add feature:constasvar to guile and chicken modules, to export constants
as variables instead of functions that return the constant value.
SWIG-1.3.29 summary:
- Numerous important bug fixes
- Few minor new features

View file

@ -1279,8 +1279,25 @@ public:
value; read-write variables become a simple procedure with
an optional argument. */
if (use_scm_interface) {
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n",
proc_name, !GetFlag(n, "feature:immutable"), var_name);
if (!goops && GetFlag(n, "feature:constasvar")) {
/* need to export this function as a variable instead of a procedure */
if (scmstub) {
/* export the function in the wrapper, and (set!) it in scmstub */
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n",
proc_name, !GetFlag(n, "feature:immutable"), var_name);
Printf(scmtext, "(set! %s (%s))\n", proc_name, proc_name);
} else {
/* export the variable directly */
Printf(f_init, "scm_c_define(\"%s\", %s(SCM_UNDEFINED));\n", proc_name, var_name);
}
} else {
/* Export the function as normal */
Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n",
proc_name, !GetFlag(n, "feature:immutable"), var_name);
}
} else {
Printf (f_init, "\t gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, %d, 0);\n",
proc_name, var_name, !GetFlag(n,"feature:immutable"));
@ -1312,7 +1329,12 @@ public:
Printv(primitive_name, "primitive:", NIL);
Printv(primitive_name, proc_name, NIL);
/* Simply re-export the procedure */
Printv(goopscode, "(define ", goops_name, " ", primitive_name, ")\n", NIL);
if ( (!emit_setters || GetFlag(n, "feature:immutable"))
&& GetFlag(n, "feature:constasvar")) {
Printv(goopscode, "(define ", goops_name, " (", primitive_name, "))\n", NIL);
} else {
Printv(goopscode, "(define ", goops_name, " ", primitive_name, ")\n", NIL);
}
Printf(goopsexport, "%s ", goops_name);
Delete(primitive_name);
Delete(class_name);
@ -1327,7 +1349,11 @@ public:
if (GetFlag(n,"feature:immutable")) {
Printv(signature, proc_name, NIL);
Printv(doc, "Returns constant ", NIL);
if (GetFlag(n, "feature:constasvar")) {
Printv(doc, "Is constant ", NIL);
} else {
Printv(doc, "Returns constant ", NIL);
}
if ((tm = Getattr(n,"tmap:varout:doc"))) {
Printv(doc,tm,NIL);
} else {
@ -1399,6 +1425,8 @@ public:
char *iname = GetChar(n,"sym:name");
SwigType *type = Getattr(n,"type");
String *value = Getattr(n,"value");
int constasvar = GetFlag(n, "feature:constasvar");
String *proc_name;
char var_name[256];
@ -1457,6 +1485,9 @@ public:
Setattr(n,"sym:name",iname);
Setattr(n,"type", nctype);
SetFlag(n,"feature:immutable");
if (constasvar) {
SetFlag(n,"feature:constasvar");
}
variableWrapper(n);
Delete(n);
}