#!./yabasic

if peek$("os")="windows" then
  lib$ = "msvcrt.dll"
else
  lib$ = "libm.so.6"
endif

res_cos = frnfn_call(lib$,"double","cos","double",2)
print "Result of cos(2):  ", res_cos
if res_cos <> cos(2) error "foreign result of cos-function does not match"

# for float values the results only match approximately,
# but the string representations (with reduced precision) are equal
if peek$("os")<>"windows" then
  if str$(frnfn_call(lib$,"float","cosf","float",2,"options","unload_library","copy_string_result")) <> str$(cos(2)) error "foreign result of cosf-function does not match"
endif

res_strstr$ = frnfn_call$(lib$,"string","strstr","string","foobar","string","ob","options","copy_string_result")
print "Result of strstr:  ",res_strstr$
if  res_strstr$ <> "obar" error "result of strstr does not match"
res_strstr$ = frnfn_call$(lib$,"string","strstr","string","foobar","string","qux","options","copy_string_result")
if  res_strstr$ <> "" error "result of strstr does not match"

if frnfn_call(lib$,"int","strlen","string","foo","string","ob") <> 3 error "result of strstr does not match"

# put string into a buffer and read it back
buf$ = frnbf_alloc$(10)
frnbf_set buf$,0,"foobar"
print "Content of buffer: ", frnbf_get$(buf$,0,10)
frnbf_free buf$
