From 73acdfbe57e373bc66442991fb28b765ed8386a0 Mon Sep 17 00:00:00 2001
From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com>
Date: Tue, 14 Dec 2010 01:33:02 -0800
Subject: [PATCH] moo.lua annotation on functions: '0' means do not bind
---
api/mdp/module.py | 31 +++++++++++++++++++++++++++++--
api/mdp/xmlwriter.py | 2 ++
api/moo.xml | 2 +-
api/mpi/luawriter.py | 6 ++++++
api/mpi/module.py | 7 ++++++-
moo/mooedit/mooeditor.c | 2 +-
6 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/api/mdp/module.py b/api/mdp/module.py
index f2c23ef3..e9f4c189 100644
--- a/api/mdp/module.py
+++ b/api/mdp/module.py
@@ -65,6 +65,7 @@ class _GTypedType(Type):
self.methods = []
self.gtype_id = gtype_id
self.short_name = short_name
+ self.annotations = {}
class Enum(_GTypedType):
def __init__(self, name, short_name, gtype_id, docs):
@@ -99,6 +100,7 @@ class Symbol(object):
self.name = name
self.c_name = c_name
self.docs = docs
+ self.annotations = {}
class FunctionBase(Symbol):
def __init__(self, name, c_name, params, retval, docs):
@@ -171,6 +173,7 @@ class Module(object):
docs = pcls.docs
parent = None
constructable = False
+ annotations = {}
for a in pcls.annotations:
pieces = a.split()
prefix = pieces[0]
@@ -180,9 +183,12 @@ class Module(object):
elif prefix == 'constructable':
assert len(pieces) == 1
constructable = True
+ elif prefix.find('.') >= 0:
+ annotations[prefix] = ' '.join(pieces[1:])
else:
raise RuntimeError("unknown annotation '%s' in class %s" % (a, name))
cls = Class(name, short_name, parent, gtype_id, docs)
+ cls.annotations = annotations
cls.constructable = constructable
self.classes.append(cls)
self.__class_dict[name] = cls
@@ -192,7 +198,16 @@ class Module(object):
short_name = getattr(pcls, 'short_name', strip_module_prefix_from_class(pcls.name, self.name))
gtype_id = getattr(pcls, 'gtype_id', make_gtype_id(pcls.name))
docs = pcls.docs
+ annotations = {}
+ for a in pcls.annotations:
+ pieces = a.split()
+ prefix = pieces[0]
+ if prefix.find('.') >= 0:
+ annotations[prefix] = ' '.join(pieces[1:])
+ else:
+ raise RuntimeError("unknown annotation '%s' in class %s" % (a, name))
cls = What(name, short_name, gtype_id, docs)
+ cls.annotations = annotations
self.boxed.append(cls)
self.__class_dict[name] = cls
@@ -209,13 +224,19 @@ class Module(object):
short_name = getattr(ptyp, 'short_name', strip_module_prefix_from_class(ptyp.name, self.name))
gtype_id = getattr(ptyp, 'gtype_id', make_gtype_id(ptyp.name))
docs = ptyp.docs
- if ptyp.annotations:
- for a in ptyp.annotations:
+ annotations = {}
+ for a in ptyp.annotations:
+ pieces = a.split()
+ prefix = pieces[0]
+ if prefix.find('.') >= 0:
+ annotations[prefix] = ' '.join(pieces[1:])
+ else:
raise RuntimeError("unknown annotation '%s' in class %s" % (a, name))
if isinstance(ptyp, dparser.Enum):
enum = Enum(name, short_name, gtype_id, docs)
else:
enum = Flags(name, short_name, gtype_id, docs)
+ enum.annotations = annotations
self.enums.append(enum)
def __parse_param_or_retval_annotation(self, annotation, param):
@@ -371,6 +392,7 @@ class Module(object):
docs = pfunc.docs
cls = None
constructor_of = None
+ annotations = {}
if pfunc.annotations:
for a in pfunc.annotations:
@@ -379,6 +401,8 @@ class Module(object):
if prefix == 'constructor-of':
assert len(pieces) == 2
constructor_of = pieces[1]
+ elif prefix.find('.') >= 0:
+ annotations[prefix] = ' '.join(pieces[1:])
else:
raise RuntimeError("unknown annotation '%s' in function %s" % (a, name))
@@ -405,11 +429,13 @@ class Module(object):
if constructor_of:
func = Function(name, c_name, params, retval, docs)
+ func.annotations = annotations
if constructor_of in self.__constructors:
raise RuntimeError('duplicated constructor of class %s' % constructor_of)
self.__constructors[constructor_of] = func
elif cls:
meth = Method(name, c_name, cls, params[1:], retval, docs)
+ meth.annotations = annotations
this_class_methods = self.__methods.get(cls)
if not this_class_methods:
this_class_methods = []
@@ -417,6 +443,7 @@ class Module(object):
this_class_methods.append(meth)
else:
func = Function(name, c_name, params, retval, docs)
+ func.annotations = annotations
self.functions.append(func)
def init_from_dox(self, blocks):
diff --git a/api/mdp/xmlwriter.py b/api/mdp/xmlwriter.py
index 99b6cb84..c59e4d99 100644
--- a/api/mdp/xmlwriter.py
+++ b/api/mdp/xmlwriter.py
@@ -128,6 +128,8 @@ class Writer(object):
dic = dict(name=func.name)
if tag != 'virtual':
dic['c_name'] = func.c_name
+ for k in func.annotations:
+ dic[k] = func.annotations[k]
self.__start_tag(tag, dic)
for p in func.params:
self.__write_param(p)
diff --git a/api/moo.xml b/api/moo.xml
index 337c8952..bd88c137 100644
--- a/api/moo.xml
+++ b/api/moo.xml
@@ -673,7 +673,7 @@
-
+
diff --git a/api/mpi/luawriter.py b/api/mpi/luawriter.py
index 8d150055..37030907 100644
--- a/api/mpi/luawriter.py
+++ b/api/mpi/luawriter.py
@@ -148,6 +148,12 @@ class Writer(object):
def __write_function(self, meth, cls, method_cfuncs):
assert not isinstance(meth, Constructor) and not isinstance(meth, VMethod)
+ bind = meth.annotations.get('moo.lua', '1')
+ if bind == '0':
+ return
+ elif bind != '1':
+ raise RuntimeError('invalid value %s for moo.lua annotation' % (bind,))
+
has_gerror_return = False
params = []
for i in range(len(meth.params)):
diff --git a/api/mpi/module.py b/api/mpi/module.py
index 3e1fccc0..3cbc3ce5 100644
--- a/api/mpi/module.py
+++ b/api/mpi/module.py
@@ -28,6 +28,7 @@ class _XmlObject(object):
def __init__(self):
object.__init__(self)
self.doc = None
+ self.annotations = {}
@classmethod
def from_xml(cls, elm, *args):
@@ -42,7 +43,11 @@ class _XmlObject(object):
raise RuntimeError('unknown element %s' % (elm.tag,))
def _parse_attribute(self, attr, value):
- return False
+ if attr.find('.') >= 0:
+ self.annotations[attr] = value
+ return True
+ else:
+ return False
def _parse_xml(self, elm, *args):
for attr, value in elm.items():
diff --git a/moo/mooedit/mooeditor.c b/moo/mooedit/mooeditor.c
index e7de43e2..4f3ae4b6 100644
--- a/moo/mooedit/mooeditor.c
+++ b/moo/mooedit/mooeditor.c
@@ -457,7 +457,7 @@ _moo_editor_get_file_watch (MooEditor *editor)
/**
- * moo_editor_create:
+ * moo_editor_create: (moo.lua 0)
*
* Returns: (transfer full)
*/