slang-users mailing list

[2005 Date Index] [2005 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[slang-users] Advice on "complex" data type integration


Hello,

I've been prototyping integration of S-Lang into GPSBabel.  I'm
impressed with the power of the presented language; it's an nice piece
of work.  Unfortunately, I'm getting all tripped up in integrating it
and am looking for some advice beyond the "C Programmer's Guide".

I have several internal data types.  They aren't horribly complicated,
but they're not trivial.  Some are dynamically generated (a waypoint
from Delorme software may have additional traits that are different
from the additional traits of a waypoint from certain XML formats).
Internally, there is extensive use of linked lists and structures hooked
together with other linked lists.

Since my "real" structures have a number of enumerated types, structures
containing structures, and other things that make themn a clunky fit to
MAKE_[IC]STRUCT_FIELD and friends, I'm kind of stumped on how to map
these on the way across the Slang border.

I'd considered making a "visible to slang" structure and exposing an
interator to the language that did a copy from the "real" C struct to
the the type I expose to make_[ci]struct_table, but that seems pretty
klunky and performance would have to be a killer.

        variable i = 0;
        for (i = gb_waypt_start(); i; i = gb_waypt_next()) {
                messsage(string(wpt.shortname));
        }

So if I plumb the "gb_" brothers above to call SLadd_istruct_table on
the struct and I copy every single member on the way in and out, it's
workable but really kind of gross.

The internal structure has things like enumerations that should probably
be exposed to slang as strings.  I have things like a time that's a
time_t plus an int for hundredths of a second, so I'd need to be able to
"shim" the timestamps on the way in and out.

So given my data types at
  http://cvs.sourceforge.net/viewcvs.py/gpsbabel/gpsbabel/defs.h?view=markup
for struct waypoint,  I'd like to be able to write Slang fragments like:

        wpt.icon = "Foo";

to set wpt_flags.icon_descr_is_dynamic, call my free routine if it was
set before, and then morph your SLang_create_slstring'ed object into one
created by my xmalloc object.

        blah = string(wpt.gc_container);

would have to read the gc_data structure in the waypoint structure, see
that gc_container is a bitfield, then call an internal function to get
the string representation of it.

        routewpt.format("an1", "line_color") = rgb

I haven't come to grips with the syntax there, but this would have to
walk through the extra data list until it found the 'an1' items attached
to this routewpt, then find the 'line_color' member in THAT struct and
generate a store to it.


Additionally, I have my own internal memory management and requiring
every string field be set and cleared via SLang_create_slstring and
SLang_free_slstring is a problem.  Is there a a way I can chain into
those two in my allocator?


I guess I could do the whole conversion at the very entry point and
exit points of the interpreter, copying the entire list to Slang-compat
types and then "undoing" it on the way back, but it just seems like I'm
getting further off balance here.

What's the most sensible way to map these things to Slang?

I've looked through several of the examples and I'm not seeing anything
at a glance that maps very well to my case that I can use for guidance.
I'd love to be able to get the power of SLang, but I'm not going to
replace my data structures and all accesses to them to get it.  Given
the elgance of the interfaces, I'm supposing there's a way to get there
from here, so I'd appreciate any pointers that can be offered.  Do you
have a good example on file of mapping things beyond simple C structs
into Slang?

Thanx in advance,
RJL


_______________________________________________
To unsubscribe, visit http://jedsoft.org/slang/mailinglists.html


[2005 date index] [2005 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]