Replies: 4 comments 5 replies
-
Indeed the Start by loading the library from your application loader file: :- initialization((
% library dependencies
logtalk_load(options(loader)),
logtalk_load(types(loader)),
...
% application source files
...
)). Then import the :- object(foo,
imports(options)).
:- uses(list, [
memberchk/2
]).
:- uses(type, [
valid/2
]).
:- public(p/1).
p(UserOptions) :-
^^check_options(UserOptions),
^^merge_options(UserOptions, Options),
...
memberchk(baz(Boolean), Options),
q(Boolean),
...
default_option(bar(42)).
default_option(baz(true)).
valid_option(baz(Boolean)) :-
valid(boolean, Boolean).
:- end_object. See the library API documentation for details. Let us know if you need additional functionality from the library. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the example :) At my current project, I'm working on an (basic) OWL reader. But OWL seems to me too heavy for simple options. In a bigger application like the "Traffic in Metaverse thing" I'm working on it may be appropriate. In this case, it would be nice to use the protocol of options to overwrite the behaviour to look into OWL for options. So: check_value(Object, Key, Vlaue) would be true if the data property Key of object Object is associated with Value, false otherwise and error if Object not exist. Cheers Hans |
Beta Was this translation helpful? Give feedback.
-
Hi, ok I see, there is a big mis-understanding on my side. I'm assuming I don't had interpreted the lgtdoc code corretly. Sorry for that. I never used predicate options, so this term is not common to me. Maybe I'm opening a problem space where no problem is. To give the context: the SWI code I'm currently port to Logtalk uses a file with "config(Key, Value) " entries. It is loaded via The Logtalk compiler had a problem with "sandboxed", a lot of errors comming in the sense "sandboxed ... cannot be reached".... And this was the very beginning of my question here :) Again, sorry for confusion. Cheers Hans |
Beta Was this translation helpful? Give feedback.
-
yep and the basic example - a stripped down from the real code - is :- object(xmppConfig).
:- public([xmpp_client/1]).
:- use_module(library(option), [option/2, option/3]).
:- dynamic config/2.
:- meta_predicate(config(*, *)).
xmpp_client(Client) :-
xmpp_client([encrypted_config(false), config('xmpp_config.txt')], Client).
xmpp_client(Options, Client) :-
option(config(File), Options), !,
load_config(File, Options).
load_config(File, _Options) :-
load_files(File, [ sandboxed(true), if(not_loaded)] ).
:- end_object. The error is (multiple times)
Cheers Hans |
Beta Was this translation helpful? Give feedback.
-
Hi,
is there some simple example code how to use the Logtalk Options library, including a "config" file and how to read and write options? I don't understand how to use it from the documentation in the handbook ;)
Remark: in SWI Prolog one way is to read a file via "load_files(File, [sandboxed(true), if(not_loaded)" containing some "config(Key, Value)." predicates and look for them via option(config(....))
Cheers
Hans
Beta Was this translation helpful? Give feedback.
All reactions