wstring in external library made with fb.

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
EkBass
Posts: 10
Joined: Oct 21, 2020 16:54
Contact:

wstring in external library made with fb.

Post by EkBass »

I am trying to pass a string from nodejs script to shared library built with FB. With normal string the output is chaotic lol. But if i did figure out it right, wstring is the way to go. I am 90% succesfull with it, but weird characters pops out time to time.

So far i can get riddof em by adding a "end tag" at the end of string at nodejs and stripping the wstring at FB.

Code: Select all

' freebasic library
#cmdline "-dll"
#include "fbgfx.bi"
#define endOfStringTag "[@@@]"
function trim_endTag(s as string) as string
declare function fb_println cdecl alias "fb_println" (s as wstring) as boolean

function trim_endTag(s as string) as string
	return mid(s, 1, (instr(s, endOfStringTag))-1)
end function

function fb_println cdecl alias "fb_println" (s as wstring) as boolean export
	print trim_endTag(s)
	return true
end function

Code: Select all

// nodejs script
/*  fb-lib expects wstrings, not regular strings so here is function to handle em. 
    "" are added at front of string incase the parameter is number, not a string */
function wstring(fb_string) {
    fb_string = fb_string + "[@@@]";
    return iconv.encode(fb_string, "utf32-le");
}
I declare function fb_println for ffi-library in my nodejs as: 'fb_println': ['bool', ['string']],

Im sure there is some more elegant way to do this, but if i dont use that endOfStringTag and strip string, my output looks horrible:
1缱𚳠缱
2缱𚳠缱
3搙����
4
5搙􆃰搙���A
6𰸂񐸄񰸆򰸊A
7Ʃ󹿸搙����򐂲A
8搙
9搙􎒘搙􊍨搙A
10����������������A
Post Reply