calling java Packages from python...

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
Zak
Posts: 13
Joined: 04 Mar 2008, 07:41
Location: Las Vegas
Contact:

calling java Packages from python...

Post by Zak »

Hello,

I have done good reading the documentation so far, or searching the forums for most of my answers, but I can not find the answer to this one anywhere:

I read in http://www.smartfoxserver.com/docs/docP ... /index.htm and also in 8.7 Tutorials: using Java classes in Actionscript, that you can call java classes from Actionscript by referncing the Packages object.

I need to be able to do this in python.

Code: Select all

scheduler = Packages.it.gotoandplay.smartfoxserver.util.scheduling
I tried something like that, but just get name errors.

Please help me if you can. Otherwise, I have to handleInternalRequest from a python extension to a new java extension, and I have very little java experience, so making an extension work will be extremely hard that way. Calling a java class will be much easier for me if I can figure out how to do it in python.


Thank you everybody, and especially Lapo :)
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Welcome aboard,
I need to be able to do this in python.
In Python you do it with the regular import and from keywords
Suppose you want to instantiate a LinkedList object from the java.util package, this is what you do

Code: Select all

from java.util import LinkedList

linkedList = LinkedList()
linkedList.add("Hello")
linkedList.add("World")
print linkedList
About the Scheduler you would go like this:

Code: Select all

from it.gotoandplay.smartfoxserver.util.scheduling import Scheduler
scheduler = Scheduler()
Check the example extensions coming with SFS PRO for more details.

HTH
Lapo
--
gotoAndPlay()
...addicted to flash games
Zak
Posts: 13
Joined: 04 Mar 2008, 07:41
Location: Las Vegas
Contact:

Post by Zak »

Nice, it works :)

Thank you Lapo.



For everybody else who comes across this thread, here's how I got a custom java class working with an SFS pro python extension:

I had the .java files, and compiled them into classes w/

Code: Select all

javac filename1.java, etc, 
then put them into a jar file:

Code: Select all

jar cf pokerhand.jar <files>

At the top of each .java file had: package ca.ualberta.cs.poker;

SFS_PRO_1.6.0/jre/lib/ext is where i moved the jar file, and set it to have execute permissions.


my extension code included

from ca.ualberta.cs.poker import Hand
from ca.ualberta.cs.poker import Card
from ca.ualberta.cs.poker import Deck
from ca.ualberta.cs.poker import HandEvaluator


I'm sure I could probably do that in one line as well, instead of 4.

from there it worked great. :)
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Yes you could go like this:
from ca.ualberta.cs.poker import Hand, Card, Deck, HandEvaluator

:)
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply