From e59a47f6b12f1f0200518cb93c25d54607603908 Mon Sep 17 00:00:00 2001
From: John Lenz
Date: Sat, 19 Aug 2006 23:32:56 +0000
Subject: [PATCH] Add feature:constasvar to guile module
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9255 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 4 ++++
Doc/Manual/Guile.html | 7 +++++++
README | 4 ++++
Source/Modules/guile.cxx | 39 +++++++++++++++++++++++++++++++++++----
4 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/CHANGES.current b/CHANGES.current
index fa436397b..cb90562f0 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -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
diff --git a/Doc/Manual/Guile.html b/Doc/Manual/Guile.html
index 32f939609..20ab716e4 100644
--- a/Doc/Manual/Guile.html
+++ b/Doc/Manual/Guile.html
@@ -405,6 +405,13 @@ In body, the first result of
See also the "multivalue" example.
+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
+Features and the %feature directive
+for info on how to apply the %feature.
+
19.6 Representation of pointers as smobs
diff --git a/README b/README
index 1b18c2210..eb324a23d 100644
--- a/README
+++ b/README
@@ -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
diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx
index ee563bffb..29ff331ea 100644
--- a/Source/Modules/guile.cxx
+++ b/Source/Modules/guile.cxx
@@ -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);
}