PrusaSlicer-NonPlainar/xs/xsp/ExtrusionLoop.xsp
Petr Ledvina 115aa6885f Implement type checking for XS objects
Type handling is mainly done using templates.
Template Slic3r::ClassTraits is used to store info about exported types (perl class name). Currently only perl class name and refference name is used.
Template values are initialized by REGISTER_CLASS macro. This macro is used in .cpp file of class ( it needs to be used exactly for each type).

Ref<type> class is used to return value as perl reference. Operator overloading is used to make c++ and XSpp happy, only pointer value should be possible to return.

Clone<type> class is used to return copy of value ( using new and copy constructor). Copy is created on assigment, this should be probably improved (memory leak on multiple assignments).
It is overloaded to be able to return type, type* and type&.

Typechecking in ExtrusionEntityCollection updated to check all passed types.
2014-04-27 19:38:56 +02:00

73 lines
1.6 KiB
Plaintext

%module{Slic3r::XS};
%{
#include <myinit.h>
#include "ExtrusionEntity.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::ExtrusionLoop} class ExtrusionLoop {
~ExtrusionLoop();
SV* arrayref()
%code{% RETVAL = THIS->polygon.to_AV(); %};
SV* pp()
%code{% RETVAL = THIS->polygon.to_SV_pureperl(); %};
void reverse()
%code{% THIS->polygon.reverse(); %};
ExtrusionPath* split_at_index(int index);
ExtrusionPath* split_at_first_point();
bool make_counter_clockwise();
Clone<Point> first_point();
Clone<Point> last_point();
bool is_perimeter();
bool is_fill();
bool is_bridge();
%{
ExtrusionLoop*
_new(CLASS, polygon_sv, role, mm3_per_mm)
char* CLASS;
SV* polygon_sv;
ExtrusionRole role;
double mm3_per_mm;
CODE:
RETVAL = new ExtrusionLoop ();
RETVAL->polygon.from_SV_check(polygon_sv);
RETVAL->role = role;
RETVAL->mm3_per_mm = mm3_per_mm;
OUTPUT:
RETVAL
Ref<Polygon>
ExtrusionLoop::polygon(...)
CODE:
if (items > 1) {
THIS->polygon.from_SV_check( ST(1) );
}
RETVAL = &(THIS->polygon);
OUTPUT:
RETVAL
ExtrusionRole
ExtrusionLoop::role(...)
CODE:
if (items > 1) {
THIS->role = (ExtrusionRole)SvUV(ST(1));
}
RETVAL = THIS->role;
OUTPUT:
RETVAL
double
ExtrusionLoop::mm3_per_mm(...)
CODE:
if (items > 1) {
THIS->mm3_per_mm = (double)SvNV(ST(1));
}
RETVAL = THIS->mm3_per_mm;
OUTPUT:
RETVAL
%}
};