danomatika / swig-openframeworks

a SWIG interface for openFrameworks with included Makefile, submodule this in your language wrapper addons
Other
39 stars 11 forks source link

Fixing some python issues #20

Closed sphaero closed 5 years ago

sphaero commented 5 years ago

it turns out a simple early define of OF_PRIMITIVE_TRIANGLE_STRIP fixes the error with python (tested 3.6.7)

also fixing an error in the make file

This has not been tested extensively but at least this now runs in OF while drawing through python, i.e.:

def draw():
    color = ofColor( random.randint(0,255), random.randint(0,255), random.randint(0,255) )
    ofSetColor(color)
    ofDrawCircle( ofGetWidth()/2, ofGetHeight()/2, 100 )
danomatika commented 5 years ago

Is removing the ofPoint & ofLog defines necessary? What were the issues with them and are they accessible without that section?

sphaero commented 5 years ago

I'd have to dig it up again but I'm confident that these methods are not available with this change.

It compiles fine without those defines but when imported errors:

Traceback (most recent call last):
  File "./openframeworks.py", line 137, in <module>
    ofPoint = ofVec3f
NameError: name 'ofVec3f' is not defined
[ error ] error importing openframeworks
Traceback (most recent call last):
  File "./tester.py", line 7, in <module>
    from openframeworks import *
  File "./openframeworks.py", line 137, in <module>
    ofPoint = ofVec3f
NameError: name 'ofVec3f' is not defined
[ error ] error importing tester

I guess it's more of an order issue?

sphaero commented 5 years ago

Ow, it was related to #19

danomatika commented 5 years ago

I guess it's more of an order issue?

Where is that section ending up in the generated .py? That might be the place to look...

sphaero commented 5 years ago

yes moving those defines to the bottom resolves it. Now to find this in the generator

danomatika commented 5 years ago

Ok cool. Then I know how to fix it. We basically need to move where lang/python.i is included in open frameworks.i. This broke when I reorganized the project into more interface files and included the lang files earlier than before as we're using typemaps for lua.

The best fix is to have "pre" and "post" lang files as obviously some sections will only work in the scripting language when the bindings are already loaded.

sphaero commented 5 years ago

Yeah, I just tried but it fails because now it's missing OF_PRIMITIVE_TRIANGLE_STRIP

NameError: name 'OF_PRIMITIVE_TRIANGLE_STRIP' is not defined

perhaps it needs a pre and post file to include?

danomatika commented 5 years ago

I split them up in the latest commit. Can you try that?

danomatika commented 5 years ago

I also fixed the makefile.

sphaero commented 5 years ago

almost, still getting the NameError: name 'OF_PRIMITIVE_TRIANGLE_STRIP' is not defined error

sphaero commented 5 years ago

I just changed this:

diff --git a/openFrameworks/lang/python/python.i b/openFrameworks/lang/python/python.i
index 7292cc8..579d88b 100644
--- a/openFrameworks/lang/python/python.i
+++ b/openFrameworks/lang/python/python.i
@@ -8,3 +8,9 @@
 %rename(__div__) *::operator/;
 %rename(__add__) *::operator+;
 %rename(__sub__) *::operator-;
+
+%pythoncode %{
+
+OF_PRIMITIVE_TRIANGLE_STRIP = None
+
+%}

I'd expect the python.i to be included before all the generated swig python code, but it doesn't?

Manually changing openFrameworks.py to define OF_PRIMITIVE_TRIANGLE_STRIP = None works however.

danomatika commented 5 years ago

It doesn't work if set in python_code.i? I just added it there...

sphaero commented 5 years ago

Weird, it does now. Good enough for me :smile:

danomatika commented 5 years ago

The lang code sections are now included after everything else in openframeworks.i. The other renames, etc need to be set before including any of the C++, otherwise they won't do anything.

If this is working, go ahead and close the issue.

sphaero commented 5 years ago

Just tried a clean build as well with success. Closing this one. Thanks for fixing!