Created
October 9, 2010 20:25
-
-
Save brianleroux/618572 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[javac] /Users/brianleroux/Repo/droidscript/src/comikit/droidscript/DroidScriptActivity.java:535: cannot find symbol | |
[javac] symbol : constructor Require(org.mozilla.javascript.Context,org.mozilla.javascript.Scriptable,comikit.droidscript.DroidScriptAssetProvider,<nulltype>,<nulltype>,boolean) | |
[javac] location: class org.mozilla.javascript.commonjs.module.Require | |
[javac] Require require = new Require(context, scope, provider, null, null, true); | |
[javac] ^ | |
[javac] 1 error | |
[javac] 2 warnings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package comikit.droidscript; | |
import java.io.IOException; | |
import java.io.Serializable; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.io.BufferedReader; | |
import org.mozilla.javascript.commonjs.module.provider.*; | |
import org.mozilla.javascript.ScriptRuntime; | |
import org.mozilla.javascript.Scriptable; | |
import org.mozilla.javascript.ScriptableObject; | |
import android.app.Activity; | |
public class DroidScriptAssetProvider implements ModuleSourceProvider, Serializable | |
{ | |
private Activity activity; | |
DroidScriptAssetProvider(Activity a) { | |
activity = a; | |
} | |
public ModuleSource getModuleSource(String moduleId, Scriptable paths, Object validator) throws IOException | |
{ | |
// activity.getAssets() | |
InputStream stream = DroidScriptIO.create().openAssetFileInputStream(activity, moduleId); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); | |
return new ModuleSource(reader, null, moduleId, null); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Interpreter setActivity(Activity activity) | |
{ | |
DroidScriptAssetProvider provider = new DroidScriptAssetProvider(activity); | |
Require require = new Require(context, scope, provider, null, null, true); | |
// Set the global JavaScript variable Activity. | |
ScriptableObject.putProperty(scope, "Activity", Context.javaToJS(activity, scope)); | |
return this; | |
} |
Took me some time to figure this out: you have to implement ModuleScriptProvider there, not ModuleSourceProvider. Funny thing is I knew this would happen back when Attila implemented it. I think we should revise this API, thanks for the reminder.
Thanks for pointing that out dude, works perfectly now =)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the problem could be due to Interpretor being a nested class but not sure. I tend to block out Java semantics.