more swig upddates.
This commit is contained in:
parent
a76b6d23dc
commit
3087d51b18
@ -2,6 +2,7 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
NDK_TOOLCHAIN_VERSION := 4.8
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_LDLIBS := -llog -landroid
|
||||
LOCAL_LDLIBS += @abs_top_builddir@/libYap.a @abs_top_builddir@/yapi.o
|
||||
LOCAL_MODULE := example
|
||||
LOCAL_SRC_FILES := yap_wrap.cpp
|
||||
|
@ -6,50 +6,84 @@ import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ScrollView;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.util.Log;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
public class SwigSimple extends Activity
|
||||
{
|
||||
TextView outputText = null;
|
||||
ScrollView scroller = null;
|
||||
YAPEngine eng = null;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
String s = "ugh";
|
||||
setContentView(R.layout.main);
|
||||
|
||||
try {
|
||||
PackageManager m = getPackageManager();
|
||||
s = getPackageName();
|
||||
PackageInfo p = m.getPackageInfo(s, 0);
|
||||
s = p.applicationInfo.dataDir;
|
||||
mgr = getResources().getAssets();
|
||||
load(mgr);
|
||||
} catch(NameNotFoundException e) {
|
||||
Log.e(TAG, "Couldn't find package information in PackageManager", e);
|
||||
}
|
||||
|
||||
outputText = (TextView)findViewById(R.id.OutputText);
|
||||
outputText.setText("Press 'Run' to start...\n");
|
||||
outputText.setText("Application " + s + "\nPress 'Run' to start...\n");
|
||||
outputText.setMovementMethod(new ScrollingMovementMethod());
|
||||
|
||||
YAPParams p = new YAPParams();
|
||||
eng = new YAPEngine( p );
|
||||
|
||||
scroller = (ScrollView)findViewById(R.id.Scroller);
|
||||
}
|
||||
|
||||
public void onRunButtonClick(View view)
|
||||
{
|
||||
outputText.append("Started...\n");
|
||||
nativeCall();
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i(TAG, "onRunButtonClick called");
|
||||
}
|
||||
outputText.append("Finished!\n");
|
||||
|
||||
// Ensure scroll to end of text
|
||||
scroller.post(new Runnable() {
|
||||
public void run() {
|
||||
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
||||
String s = "['/assets/share/Yap/lists'].\n";
|
||||
outputText.append(s);
|
||||
YAPQuery q = eng.query(s);
|
||||
q.next();
|
||||
String s = "member(X, [1,2,3]).\n";
|
||||
outputText.append(s);
|
||||
YAPQuery q = eng.query(s);
|
||||
q.next();
|
||||
String sn =
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Calls into C/C++ code */
|
||||
public void nativeCall()
|
||||
{
|
||||
// YAPParams p = new YAPParams();
|
||||
//YAPEngine t = new YAPEngine( p ); // TODO
|
||||
}
|
||||
|
||||
/** static constructor */
|
||||
static {
|
||||
System.loadLibrary("android");
|
||||
System.loadLibrary("log");
|
||||
System.loadLibrary("example");
|
||||
}
|
||||
|
||||
private static native void load(AssetManager mgr);
|
||||
|
||||
private AssetManager mgr;
|
||||
|
||||
private static final String TAG = "SwigSimple";
|
||||
|
||||
}
|
||||
|
20
packages/swig/python/demo.py
Normal file
20
packages/swig/python/demo.py
Normal file
@ -0,0 +1,20 @@
|
||||
# python commands
|
||||
|
||||
import sys
|
||||
import yap
|
||||
|
||||
engine = yap.YAPEngine();
|
||||
# engine = yap.YAPEngine(yap.YAPParams());
|
||||
|
||||
def go():
|
||||
while True:
|
||||
s = raw_input("Prolog Query: ")
|
||||
q = engine.query(s)
|
||||
while q.next():
|
||||
vs = q.namedVars();
|
||||
while vs.length() > 0:
|
||||
eq = vs.car()
|
||||
print eq.text()
|
||||
print eq.getArg(1).text() + " = " + eq.getArg(2).text()
|
||||
vs = vs.cdr()
|
||||
print "no more answers"
|
Reference in New Issue
Block a user