Basically you need to dereference the pointer and apply pointer arithmetic. It's doable from newLISP, but this requires behavior which is tied to the size of pointers for the platform the interpreter is running on. For the platforms I know of, you need to know this:
32 bit X86 is 4 bytes and requires get-int function call
64 bit X86 is 8 bytes and requires get-long function call
Ideally, this is something that should be added to the interpreter's builtin functions. The user should at least have a portable way of determining this platform's pointer sizes.
First the C code of the compiled shared library:
Now the code for the newLISP code:
Code: Select all
(import "./test.so" "xyz")
(constant 'PointerSize 8)
(constant 'get-pointer (fn (x) (get-long x)))
(set 'i 0)
(until (= (get-pointer (+ (address xyz) i)) 0)
(println (get-string (get-pointer (+ (address xyz) i))))
(set 'i (+ i PointerSize))
This is just a sample of how to get the strings. I am assuming that the database library you are using is passing an array of C strings, with the last one being a null pointer. If you are running newLISP on a 32 bit OS, you will need to change the PointerSize to 4 and the get-pointer function to use get-int instead.