SRL Archive - Research & Development Lounge

Python Bindings for SMART


BenLand100

2010-12-29 22:32:29

Since there seems to be a growing desire to move to python, I figured I would jump the gun a bit since I had time and get SMART to work from Python. All this really required was converting all exported methods to the cdecl calling convention (since python can't invoke stdcall methods from linux) and preserving the stdcall convention for use in Simba/SCAR, along with writing the bindings themselves. All I can say is THANK GOD FOR REGEX.

Anyway, the SMART repos (http://blanddns.no-ip.org:81/repos/public-smart) and most recent (v6.5) SMART binaries reflects these additions. The bindings are also in the test-apps folder in the repos, however for ease of viewing, I will attach them here. You python gurus might know a "better" (read: less code) way to do this, but I generated it mostly with regex anyway, and it should work like a charm (I tested it, sort of).

Cheers.

i luffs yeww

2010-12-29 22:47:40

Well if all you changed was exporting, it should be fine, as SMART has been fine with Python since 6.3, as you saw.

Thanks.

pyroryan

2010-12-29 22:48:07

Nice work :P!

BenLand100

2010-12-29 23:21:43

From: i luffs yeww
Well if all you changed was exporting, it should be fine, as SMART has been fine with Python since 6.3, as you saw.

Thanks.

Well, I know it's always loaded up, but I've personally never seen anything really use SMART from python (at least not a significant portion of the api). I basically wanted to use CDLL from both linux and windows to keep from killing the stack.

i luffs yeww

2010-12-29 23:26:41

Well I've gotten mouse, color, and keyboard to work through lib/pymml. I don't think any of the things in SMART are used yet, and they won't need to be for SPyRL. Of course they will need to be used for reflection, but I don't think it will be like smart.scar how it is now with a bunch of "overwrites," but I haven't really ever looked into how SRL and SMART interact.

All I know is that all the basic things that I've tested (color/mouse/keyboard, I'll test dtm/bmp/ocr when I have time) work fine with how pymml is now.

BenLand100

2010-12-29 23:34:26

Oh, I forget, pymml basically uses the binary mml, doesn't it? so it comes with a plugin loader? haha.

Nava2

2010-12-30 00:13:29

From: BenLand100
Oh, I forget, pymml basically uses the binary mml, doesn't it? so it comes with a plugin loader? haha.


Not sure, but every function still needs to be written to have python bindings no matter what you do. As such, we still need to implement it seperately. What would still need to be implemented is how SMART and libmml interact via the TMufasaClients in Python.

i luffs yeww

2010-12-30 02:50:00

pyMML just (for the most part) calls functions from libMML, which is just full of all functions in Simba, compiled into a .dll/.so. So as long as SMART can function directly with what's in Simba, it should be just fine?

Wizzup?

2011-01-01 07:24:11

Na, the core MML does not have a plugin loader. It's rather specific to Simba. Plus, the plugin loader uses pascal stuff anyway. Just using the ctypes from Python like I did with the SmartMouse / MMLMouse combo.

Those bindings look good though. Auto generated?

BenLand100

2011-01-01 19:31:49

Largely autogenerated. Of course I did some manual tweaking, but I made about 85% of it from manipulating the STD_Wrapper.* files, which in turn were largely autogenerated ;)

Sir R. M8gic1an

2011-01-02 02:13:47

Smart seems to be getting a lot of development lately, maybe you'll want to re-add the Smart forums to the Development category?

I wouldn't mind doing that, but the shot is yours to call. ;)

~RM

BenLand100

2011-01-02 03:05:53

Well, I'm on break atm. Development will drop off steeply once classes start back up. IDC how the forums are arranged though, haha

bevardis

2011-01-04 14:05:28

What about reflection bindings? <><

BenLand100

2011-01-04 17:02:22

From: bevardis
What about reflection bindings? <><

They're in there, reflection is part of SMART

Nava2

2011-01-04 22:32:17

Ben, I just started reading these over, these are awesome! Thanks for this. This will really allow us to move forward with Python. :)

bevardis

2011-01-05 06:19:56

Traceback (most recent call last):
File "C:\Documents and Settings\Administrator\My Documents\Downloads\Simba.i386-win32.2011-01-03_21_51\Plugins\test-python.py", line 584, in <module>
smart = Smart('http://world19.runescape.com/', 'plugin.js?param=o0,a2,m0', 765, 503, '')
File "C:\Documents and Settings\Administrator\My Documents\Downloads\Simba.i386-win32.2011-01-03_21_51\Plugins\test-python.py", line 52, in __init__
self._dll.setJVMPath.argtypes = [c_char_p]
File "C:\Python27\lib\ctypes\__init__.py", line 366, in __getattr__
func = self.__getitem__(name)
File "C:\Python27\lib\ctypes\__init__.py", line 371, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'setJVMPath' not found


Wrong libsmart.dll?
What configuration do I need to use to get this work?
Python 2.7, libsmart.dll from nightlies/public svn

BenLand100

2011-01-05 12:26:40

That looks like you got the wrong libsmart.dll, setJVMPath was added in 6.5
If in doubt: http://blanddns.no-ip.org:81/files/libsmart.dll

bevardis

2011-01-17 14:40:41

I am still unable to get this running.

Tried both windows and linux.

I add the *.py and libsmart.dll (.so on linux) to one folder and try to run, just won't work. Same error. What's more to it?

Also, If I would manage to get it running, how would I use functions like
R_FindRandoms
MakeCompass ('s')

etc.

Nava2

2011-01-17 16:07:55

From: bevardis
Also, If I would manage to get it running, how would I use functions like
R_FindRandoms
MakeCompass ('s')

etc.


You wouldnt.. those are not available in python.