more swig upddates.
This commit is contained in:
parent
a76b6d23dc
commit
3087d51b18
@ -2,6 +2,7 @@
|
|||||||
LOCAL_PATH := $(call my-dir)
|
LOCAL_PATH := $(call my-dir)
|
||||||
NDK_TOOLCHAIN_VERSION := 4.8
|
NDK_TOOLCHAIN_VERSION := 4.8
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_LDLIBS := -llog -landroid
|
||||||
LOCAL_LDLIBS += @abs_top_builddir@/libYap.a @abs_top_builddir@/yapi.o
|
LOCAL_LDLIBS += @abs_top_builddir@/libYap.a @abs_top_builddir@/yapi.o
|
||||||
LOCAL_MODULE := example
|
LOCAL_MODULE := example
|
||||||
LOCAL_SRC_FILES := yap_wrap.cpp
|
LOCAL_SRC_FILES := yap_wrap.cpp
|
||||||
|
@ -6,22 +6,43 @@ import android.view.View;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.text.method.ScrollingMovementMethod;
|
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
|
public class SwigSimple extends Activity
|
||||||
{
|
{
|
||||||
TextView outputText = null;
|
TextView outputText = null;
|
||||||
ScrollView scroller = null;
|
ScrollView scroller = null;
|
||||||
|
YAPEngine eng = null;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState)
|
public void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
String s = "ugh";
|
||||||
setContentView(R.layout.main);
|
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 = (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());
|
outputText.setMovementMethod(new ScrollingMovementMethod());
|
||||||
|
YAPParams p = new YAPParams();
|
||||||
|
eng = new YAPEngine( p );
|
||||||
|
|
||||||
scroller = (ScrollView)findViewById(R.id.Scroller);
|
scroller = (ScrollView)findViewById(R.id.Scroller);
|
||||||
}
|
}
|
||||||
@ -29,27 +50,40 @@ public class SwigSimple extends Activity
|
|||||||
public void onRunButtonClick(View view)
|
public void onRunButtonClick(View view)
|
||||||
{
|
{
|
||||||
outputText.append("Started...\n");
|
outputText.append("Started...\n");
|
||||||
nativeCall();
|
if (BuildConfig.DEBUG) {
|
||||||
|
Log.i(TAG, "onRunButtonClick called");
|
||||||
|
}
|
||||||
outputText.append("Finished!\n");
|
outputText.append("Finished!\n");
|
||||||
|
|
||||||
// Ensure scroll to end of text
|
// Ensure scroll to end of text
|
||||||
scroller.post(new Runnable() {
|
scroller.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
scroller.fullScroll(ScrollView.FOCUS_DOWN);
|
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 constructor */
|
||||||
static {
|
static {
|
||||||
|
System.loadLibrary("android");
|
||||||
|
System.loadLibrary("log");
|
||||||
System.loadLibrary("example");
|
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