[Ipe-discuss] Creating arcs in lua ipelet

Otfried Cheong otfried at ipe.airpost.net
Thu Oct 28 11:42:42 CEST 2010


On 10/26/2010 10:25 PM, [cristo] wrote:
> I am trying to create an ipe.Arc in a lua ipelet using the following code:
>
> arc_shape = {}
>
> table.insert(arc_shape, { type="curve", closed=false })
> table.insert(arc_shape, { type="arc", arc=ipe.Arc(m, points[j],
> points[i]) })
> table.insert(arcs, ipe.Path(model.attributes, arc_shape))
> [...]
>
> The line mentioned in the error is in which ipe.Path is created. Does
> anyone can see where am I wrong?

Quite a few things, actually.  Note that in Lua, tables contain elements 
indexed by integers 1,2,3,... and elements indexed by a key (like 
"type", "closed", "arc") at the same time.

The following is a working example:

m = ipe.Matrix()
p = ipe.Vector(0,1)
q = ipe.Vector(1,0)

arc = { type="arc", arc=ipe.Arc(m, p, q), p, q }
subpath = { type="curve", closed=false, arc }
shape = { subpath }
path = ipe.Path({}, shape)

Observe that "shape" is a table that contains one element (because there 
is only one subpath).  This subpath is a table that has two elements 
with keys, and one element at index 1 (namely the arc).
The arc has two elements with keys "type" and "arc", but must also have 
the two endpoints as elements at index 1 and index 2.

Cheers,
  Otfried







More information about the Ipe-discuss mailing list