diff --git a/pyste/NEWS b/pyste/NEWS index 28bcbbfe..3505706d 100644 --- a/pyste/NEWS +++ b/pyste/NEWS @@ -1,3 +1,7 @@ +23 May 2003 +Support for global variables added. +Various bug fixes. + 08 May 2003 Fixed bug where in a certain cases the GCCXMLParser would end up with multiple declarations of the same class diff --git a/pyste/doc/global_variables.html b/pyste/doc/global_variables.html new file mode 100644 index 00000000..84b3b9d3 --- /dev/null +++ b/pyste/doc/global_variables.html @@ -0,0 +1,49 @@ + +
+ +
+ |
+ + Global Variables + | +
![]() |
+ ![]() |
+ ![]() |
+
+To export global variables, use the Var construct:
+
+ Var("myglobal", "foo.h")
+
++Beware of non-const global variables: changes in Python won't reflect in C++! +If you really must change them in Python, you will have to write some accessor +functions, and export those.
+![]() |
+ ![]() |
+ ![]() |
+
Copyright © 2003 Bruno da Silva de Oliveira
Copyright © 2002-2003 Joel de Guzman
+Permission to copy, use, modify, sell and distribute this document
+ is granted provided this copyright notice appears in all copies. This document
+ is provided "as is" without express or implied warranty, and with
+ no claim as to its suitability for any purpose.
Pyste supports the following features:
-| + Global Variables + | +
Copyright © 2003 Bruno da Silva de Oliveira
Copyright © 2002-2003 Joel de Guzman
diff --git a/pyste/src/ClassExporter.py b/pyste/src/ClassExporter.py
index c5536f6a..e6d5bb6b 100644
--- a/pyste/src/ClassExporter.py
+++ b/pyste/src/ClassExporter.py
@@ -751,7 +751,7 @@ class _VirtualWrapperGenerator(object):
all_methods = [x for x in self.class_.members if IsVirtual(x)]
for base in self.bases:
- base_methods = [x.Copy() for x in self.bases.members if IsVirtual(x)]
+ base_methods = [x.Copy() for x in base if IsVirtual(x)]
for base_method in base_methods:
base_method.class_ = self.class_.FullName()
all_methods.append(base_method)
diff --git a/pyste/src/HeaderExporter.py b/pyste/src/HeaderExporter.py
index 1d5fda1b..141f4da4 100644
--- a/pyste/src/HeaderExporter.py
+++ b/pyste/src/HeaderExporter.py
@@ -2,6 +2,7 @@ from Exporter import Exporter
from ClassExporter import ClassExporter
from FunctionExporter import FunctionExporter
from EnumExporter import EnumExporter
+from VarExporter import VarExporter
from infos import *
from declarations import *
import os.path
@@ -47,6 +48,7 @@ class HeaderExporter(Exporter):
Class : ClassExporter,
Enumeration : EnumExporter,
Function : FunctionExporter,
+ Variable : VarExporter,
}
exporter_class = dispatch_table.get(type(decl))
diff --git a/pyste/src/VarExporter.py b/pyste/src/VarExporter.py
new file mode 100644
index 00000000..6e4bf370
--- /dev/null
+++ b/pyste/src/VarExporter.py
@@ -0,0 +1,31 @@
+from Exporter import Exporter
+from settings import *
+
+
+#==============================================================================
+# VarExporter
+#==============================================================================
+class VarExporter(Exporter):
+ '''Exports a global variable.
+ '''
+
+ def __init__(self, info):
+ Exporter.__init__(self, info)
+
+
+ def Export(self, codeunit, exported_names):
+ if self.info.exclude: return
+ decl = self.GetDeclaration(self.info.name)
+ if not decl.type.const:
+ msg = '---> Warning: The global variable "%s" is non-const:\n' \
+ ' changes in Python will not reflect in C++.'
+ print msg % self.info.name
+ print
+ rename = self.info.rename or self.info.name
+ code = self.INDENT + namespaces.python
+ code += 'scope().attr("%s") = %s;\n' % (rename, self.info.name)
+ codeunit.Write('module', code)
+
+
+ def Order(self):
+ return self.info.name
diff --git a/pyste/src/declarations.py b/pyste/src/declarations.py
index a037c04d..b8f1ef9d 100644
--- a/pyste/src/declarations.py
+++ b/pyste/src/declarations.py
@@ -243,8 +243,8 @@ class Method(Function):
self.name,
self.class_,
self.result,
- self.params[:],
- self.visib,
+ self.parameters[:],
+ self.visibility,
self.virtual,
self.abstract,
self.static,
diff --git a/pyste/src/exporterutils.py b/pyste/src/exporterutils.py
index 6dafe39a..27bdd095 100644
--- a/pyste/src/exporterutils.py
+++ b/pyste/src/exporterutils.py
@@ -10,11 +10,11 @@ from declarations import *
# FunctionWrapper
#==============================================================================
class FunctionWrapper(object):
- '''Holds information about a wrapper for a function or a method. It is in 2
- parts: the name of the Wrapper, and its code. The code is placed in the
- declaration section of the module, while the name is used to def' the
- function or method (with the pyste namespace prepend to it). If code is None,
- the name is left unchanged.
+ '''Holds information about a wrapper for a function or a method. It is
+ divided in 2 parts: the name of the Wrapper, and its code. The code is
+ placed in the declaration section of the module, while the name is used to
+ def' the function or method (with the pyste namespace prepend to it). If
+ code is None, the name is left unchanged.
'''
def __init__(self, name, code=None):
diff --git a/pyste/src/infos.py b/pyste/src/infos.py
index c0c8013d..d4534532 100644
--- a/pyste/src/infos.py
+++ b/pyste/src/infos.py
@@ -6,6 +6,7 @@ from FunctionExporter import FunctionExporter
from IncludeExporter import IncludeExporter
from EnumExporter import EnumExporter
from HeaderExporter import HeaderExporter
+from VarExporter import VarExporter
from exporterutils import FunctionWrapper
from utils import makeid
@@ -86,7 +87,7 @@ class IncludeInfo(DeclarationInfo):
exporter = IncludeExporter(InfoWrapper(self))
exporters.exporters.append(exporter)
-
+
#==============================================================================
# templates
#==============================================================================
@@ -148,6 +149,19 @@ class HeaderInfo(DeclarationInfo):
exporters.exporters.append(exporter)
+#==============================================================================
+# VarInfo
+#==============================================================================
+class VarInfo(DeclarationInfo):
+
+ def __init__(self, name, include):
+ DeclarationInfo.__init__(self)
+ self._Attribute('name', name)
+ self._Attribute('include', include)
+ exporter = VarExporter(InfoWrapper(self))
+ exporters.exporters.append(exporter)
+
+
#==============================================================================
# InfoWrapper
#==============================================================================
diff --git a/pyste/src/pyste.py b/pyste/src/pyste.py
index 62cf3439..6aa4f7b6 100644
--- a/pyste/src/pyste.py
+++ b/pyste/src/pyste.py
@@ -2,9 +2,12 @@
Pyste version %s
Usage:
- pyste [options] --module=