generator: Add support for fixed length arrays as method parameters
Fixed length arrays are available in gobject introspection and are already converted by the bindinator tool. The array_len attribute was only used in structs. This adds support for them as method parameters, generating the correct code for them. Fixes issue #98. Signed-off-by: Bertrand Lorentz <bertrand.lorentz@gmail.com>
This commit is contained in:
parent
87275786b7
commit
06b966beef
2 changed files with 13 additions and 1 deletions
1
gapi.xsd
1
gapi.xsd
|
@ -296,6 +296,7 @@
|
|||
<xs:attribute name="type" type="xs:string"/>
|
||||
<xs:attribute name="name" type="xs:string"/>
|
||||
<xs:attribute name="array" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute name="array_len" type="xs:positiveInteger" use="optional"/>
|
||||
<xs:attribute name="null_term_array" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute name="ellipsis" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute name="owned" type="xs:boolean" use="optional"/>
|
||||
|
|
|
@ -33,6 +33,8 @@ namespace GtkSharp.Generation {
|
|||
public ArrayParameter (XmlElement elem) : base (elem)
|
||||
{
|
||||
null_terminated = elem.GetAttributeAsBoolean ("null_term_array");
|
||||
if (elem.HasAttribute ("array_len"))
|
||||
FixedArrayLength = Int32.Parse (elem.GetAttribute ("array_len"));
|
||||
}
|
||||
|
||||
public override string MarshalType {
|
||||
|
@ -50,12 +52,19 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
public int? FixedArrayLength { get; private set; }
|
||||
|
||||
public override string[] Prepare {
|
||||
get {
|
||||
if (CSType == MarshalType)
|
||||
if (CSType == MarshalType && !FixedArrayLength.HasValue)
|
||||
return new string [0];
|
||||
|
||||
var result = new List<string> ();
|
||||
|
||||
if (FixedArrayLength.HasValue) {
|
||||
result.Add (String.Format ("{0} = new {1}[{2}];", Name, MarshalType.TrimEnd ('[', ']'), FixedArrayLength));
|
||||
return result.ToArray ();
|
||||
}
|
||||
result.Add (String.Format ("int cnt_{0} = {0} == null ? 0 : {0}.Length;", CallName));
|
||||
result.Add (String.Format ("{0}[] native_{1} = new {0} [cnt_{1}" + (NullTerminated ? " + 1" : "") + "];", MarshalType.TrimEnd('[', ']'), CallName));
|
||||
result.Add (String.Format ("for (int i = 0; i < cnt_{0}; i++)", CallName));
|
||||
|
@ -75,6 +84,8 @@ namespace GtkSharp.Generation {
|
|||
get {
|
||||
if (CSType != MarshalType)
|
||||
return "native_" + CallName;
|
||||
else if (FixedArrayLength.HasValue)
|
||||
return base.CallString;
|
||||
else
|
||||
return CallName;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue