|Subject:||Programmatically consulting a prolog file|
|Date:||Fri, 9 Apr 2010 23:31:13 +1000|
I'm trying to access Prolog from within my C++ code (Using Visual C++ 2008 Express). I have it mostly working now. I am able to successfully write a C++ program, build it (In MSVC, not using glpc) and call predicates like write/1 and absolute_file_name/2. However, I have my own Prolog files I wish to consult from within the C ++code.
I figured I'd just call the consult/1 predicate with the name of the .pl file. But the Pl_Query_Call returns a PL_EXCEPTION. I even tried using absolute_file_name/2 to construct the filename for consult/1 (To be 100% sure I was using the right name). Sure enough, absolute_file_name/2 can find the file, but consult/1 still fails.
Here is an excerpt from my code:
//This correctly unifies arg with the absolute file name of new_main.pl, e:/new_main.pl
func = Pl_Find_Atom("absolute_file_name");
arg = Pl_Mk_String("new_main.pl");
arg = Pl_Mk_Variable();
res = Pl_Query_Call(func, 2, arg);
//This should load in all predicates in the file new_main.pl
func = Pl_Find_Atom("consult");
arg = arg;
res = Pl_Query_Call(func, 1, arg);
Yet, it just returns and exception. Even if I try to proceed and try to Pl_Find_Atom on any of the predicates from the file, they just fail.
I also tried adding the argument "--init-goal consult('e:/new_main.pl')" to argv in Pl_Start_Prolog. No dice there either.
I'd really like to do my work from with the MSVC IDE, so any help with programmatically consulting the prolog file would be much appreciated.
Meet local singles online. Browse profiles for FREE!
|[Prev in Thread]||Current Thread||[Next in Thread]|