Skip to content

Commit

Permalink
formatting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Feb 16, 2024
1 parent 2e08fe3 commit c9e8c0d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
43 changes: 23 additions & 20 deletions hxpy/Python.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package hxpy;

import cpp.Callable;

@:buildXml("<include name='${haxelib:hxpy}/hxpy/Build.xml' />")
@:include("Python.h")
@:keep
Expand Down Expand Up @@ -69,8 +71,8 @@ extern class Python
public static inline function runSimpleFile(filetoParse:String):Void {
@:privateAccess
File.runSimpleFile(filetoParse);
}

}
/**
*Function for closing a Python instance.
*/
Expand All @@ -82,33 +84,34 @@ extern class Python
@:cppFileCode('
#define PY_SSIZE_T_CLEAN
#ifdef _DEBUG
#undef _DEBUG
#include <Python.h>
#define _DEBUG
#undef _DEBUG
#include <Python.h>
#define _DEBUG
#else
#include <Python.h>
#include <Python.h>
#endif
#include <string>
#include <iostream>
using std::string;
using namespace std;
')
@:keep
class File {
/**
* Function for loading Python code from a file.
* @param filetoParse The path of your Python script. (eg: script.py)
*/
private static function runSimpleFile(filetoParse:String) {
untyped __cpp__('
PyObject *obj = Py_BuildValue("s", filetoParse.c_str());
FILE* PScriptFile = _Py_fopen_obj(obj, "r+");
if(PScriptFile){
PyRun_SimpleFile(PScriptFile, filetoParse);
fclose(PScriptFile);
}
else{
std::cout << "File Not Found!";
}
');
}
}
private static function runSimpleFile(filetoParse:String) {
untyped __cpp__('
PyObject *obj = Py_BuildValue("s", filetoParse.c_str());
FILE* PScriptFile = _Py_fopen_obj(obj, "r+");
if(PScriptFile){
PyRun_SimpleFile(PScriptFile, filetoParse);
fclose(PScriptFile);
}
else{
std::cout << "File Not Found!";
}
');
}
}
6 changes: 3 additions & 3 deletions test/demos/extending python/src/Main.hx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package;

import hxpy.Python;
import hxpy.Python.File;
import hxpy.Python;

class Main {
public static function main():Void {
//initializes the python instance
Python.initialize();
//runs code path to script file
File.runSimpleFile("script.py");
//runs code path to script file
Python.runSimpleFile("script.py");
//closes the python instance
Python.finalize();
}
Expand Down

0 comments on commit c9e8c0d

Please sign in to comment.