Add support for CFFI finalizer
This commit is contained in:
@@ -373,6 +373,9 @@ class CFFI {
|
||||
}
|
||||
|
||||
|
||||
@:noCompletion @:dox(hide) public static var lime_cffi_set_finalizer = System.load ("lime", "lime_cffi_set_finalizer", 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -505,7 +508,7 @@ class CFFI {
|
||||
|
||||
#end
|
||||
|
||||
newFields.push ( { name: cffiName, access: [ APrivate, AStatic ], kind: FieldType.FVar (cffiType, Context.parse (cffiExpr, pos)), pos: pos } );
|
||||
newFields.push ( { name: cffiName, access: [ APrivate, AStatic ], kind: FieldType.FVar (cffiType, Context.parse (cffiExpr, field.pos)), pos: field.pos } );
|
||||
|
||||
if (type.result.toString () != "Void" && type.result.toString () != "cpp.Void") {
|
||||
|
||||
@@ -531,7 +534,32 @@ class CFFI {
|
||||
}
|
||||
|
||||
field.access.push (AInline);
|
||||
fun.expr = Context.parse (expr, pos);
|
||||
fun.expr = Context.parse (expr, field.pos);
|
||||
|
||||
} else if (m.name == ":finalizer") {
|
||||
|
||||
for (otherField in fields) {
|
||||
|
||||
if (otherField.name == "new") {
|
||||
|
||||
switch (otherField.kind) {
|
||||
|
||||
case FFun (fun):
|
||||
|
||||
var fieldName = field.name;
|
||||
var expr = fun.expr.toString ();
|
||||
expr = expr.substring (0, expr.lastIndexOf ("}")) + '\n\t__finalizerTrigger = lime.system.CFFI.lime_cffi_set_finalizer ($fieldName);\n}';
|
||||
fun.expr = Context.parse (expr, field.pos);
|
||||
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
newFields.push ({ name: "__finalizerTrigger", access: [ APrivate ], kind: FieldType.FVar (TPath ({ pack: [ ], name: "Dynamic" }), null), pos: field.pos });
|
||||
|
||||
}
|
||||
|
||||
@@ -725,7 +753,7 @@ class CFFI {
|
||||
|
||||
typeString += typeResult.toString ();
|
||||
|
||||
return { args: typeArgs, result: typeResult, string: typeString, signature: typeSignature, };
|
||||
return { args: typeArgs, result: typeResult, string: typeString, signature: typeSignature };
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
#include <utils/LZMA.h>
|
||||
#include <vm/NekoVM.h>
|
||||
|
||||
DEFINE_KIND (k_finalizer);
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
@@ -168,6 +170,22 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void lime_cffi_finalizer (value abstract) {
|
||||
|
||||
val_call0 ((value)val_data (abstract));
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_cffi_set_finalizer (value callback) {
|
||||
|
||||
value abstract = alloc_abstract (k_finalizer, callback);
|
||||
val_gc (abstract, lime_cffi_finalizer);
|
||||
return abstract;
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_clipboard_get_text () {
|
||||
|
||||
if (Clipboard::HasText ()) {
|
||||
@@ -1245,6 +1263,7 @@ namespace lime {
|
||||
DEFINE_PRIME2 (lime_bytes_from_data_pointer);
|
||||
DEFINE_PRIME1 (lime_bytes_get_data_pointer);
|
||||
DEFINE_PRIME1 (lime_bytes_read_file);
|
||||
DEFINE_PRIME1 (lime_cffi_set_finalizer);
|
||||
DEFINE_PRIME0 (lime_clipboard_get_text);
|
||||
DEFINE_PRIME1v (lime_clipboard_set_text);
|
||||
DEFINE_PRIME2 (lime_file_dialog_open_file);
|
||||
|
||||
Reference in New Issue
Block a user