Skip to content

Commit

Permalink
yeah
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Feb 16, 2025
1 parent 6e9f570 commit 36a2f1a
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hxpy/PyCallable.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import cpp.RawPointer;
@:keep
extern class PyCallable {
@:native('PyCallable_Check')
static function check(o:RawPointer<PyObject>):Int;
static function check(o:RawPointer<PyObject>):Bool;
}
7 changes: 7 additions & 0 deletions hxpy/PyLong.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hxpy;

import cpp.SizeT;
import cpp.RawPointer;

@:buildXml("<include name='${haxelib:hxpy}/hxpy/Build.xml' />")
Expand All @@ -11,4 +12,10 @@ extern class PyLong {

@:native('PyLong_AsLong')
static function asLong(obj:RawPointer<PyObject>):Int;

@:native('PyLong_AsSize_t')
static function asSizeT(obj:RawPointer<PyObject>):SizeT;

@:native('PyLong_AsSsize_t')
static function asSsizeT(obj:RawPointer<PyObject>):PySsizeT;
}
7 changes: 7 additions & 0 deletions hxpy/PySsizeT.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hxpy;

@:buildXml("<include name='${haxelib:hxpy}/hxpy/Build.xml' />")
@:include("Python.h")
@:native("Py_ssize_t")
@:scalar @:coreType @:notNull
extern abstract PySsizeT from(Int) to(Int) {}
3 changes: 2 additions & 1 deletion test/pure embedding/build.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
-D analyzer-optimize
-main Main
--cpp bin
--library hxpy
--library hxpy
--macro CopyFile.run()
6 changes: 6 additions & 0 deletions test/pure embedding/multiply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def multiply(a,b):
print("Will compute", a, "times", b)
c = 0
for i in range(0, a):
c = c + b
return c
18 changes: 18 additions & 0 deletions test/pure embedding/src/CopyFile.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package;

import haxe.macro.Expr;
import haxe.macro.Compiler;
import sys.io.File;
import sys.FileSystem;

class CopyFile {
public static macro function run():Expr {
var outputDir:String = Compiler.getOutput();
if(!FileSystem.exists(outputDir)){
FileSystem.createDirectory(outputDir);
}
File.copy("multiply.py", '${outputDir}/multiply.py');

return macro a;
}
}
5 changes: 4 additions & 1 deletion test/pure embedding/src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import hxpy.PyObject;
import hxpy.PyTuple;
import cpp.RawPointer;

/**
* @see https://docs.python.org/3/extending/embedding.html#pure-embedding
*/
class Main {
static var pName:RawPointer<PyObject>;
static var pModule:RawPointer<PyObject>;
Expand All @@ -33,7 +36,7 @@ class Main {

if (pModule != null) {
pFunc = PyObject.getAttrString(pModule, Sys.args()[2]);
if (pFunc != null && (PyCallable.check(pFunc) <= 1)) {
if (pFunc != null && PyCallable.check(pFunc)) {
pArgs = PyTuple.newPyTuple(Sys.args().length - 3);
for (i in 0...Sys.args().length - 3) {
pValue = PyLong.fromLong(Std.parseInt(Sys.args()[i + 3]));
Expand Down

0 comments on commit 36a2f1a

Please sign in to comment.