EkBass
Bronze Coder
Hi.
I thought to try out to write simple FreeBASIC dll. I mostly use the neat GFX library of it with my dll. Via python/nodejs i can use it's power pretty easily.
I am just curious, has anyone tested is it possible to gain more calculation speed with such a dll? If we compare scripting languages and compiled languages in such a terms, it is a bit boring race due C and such whipes python/nodejs with a floor.
But, it takes its own computing power to transfer the calculations and all data from script to dll.
Before i spend couple of hours with this, i thought to ask has anyone tried here it yet?
If you want to try out, here is short example codes.
I thought to try out to write simple FreeBASIC dll. I mostly use the neat GFX library of it with my dll. Via python/nodejs i can use it's power pretty easily.
I am just curious, has anyone tested is it possible to gain more calculation speed with such a dll? If we compare scripting languages and compiled languages in such a terms, it is a bit boring race due C and such whipes python/nodejs with a floor.
But, it takes its own computing power to transfer the calculations and all data from script to dll.
Before i spend couple of hours with this, i thought to ask has anyone tried here it yet?
If you want to try out, here is short example codes.
Code:
' freebasic
#cmdline "-dll"
declare function fb_screen cdecl alias "fb_screen" (s as integer) as boolean
declare function fb_console cdecl alias "fb_console" () as boolean
declare function fb_print cdecl alias "fb_print" (s as wstring) as boolean
declare function fb_sleep cdecl alias "fb_sleep" (s as integer) as boolean
declare function fb_cls cdecl alias "fb_cls" () as boolean
function fb_screen cdecl alias "fb_screen"(s as integer) as boolean export
dim r_val as boolean = false
if(s = 1 or s = 2 or s > 6 and s < 22) then
screen s
r_val = true
end if
return r_val
end function
function fb_console cdecl alias "fb_console" () as boolean export
screen 0
return true
end function
function fb_print cdecl alias "fb_print" (s as wstring) as boolean export
print s;
return true
end function
function fb_sleep cdecl alias "fb_sleep" (s as integer) as boolean export
sleep s
return true
end function
function fb_cls cdecl alias "fb_cls" () as boolean export
cls
return true
end function
JavaScript:
const ffi = require('ffi-napi');
const iconv = require('iconv-lite');
const path = require('path');
// Adjust the path to your shared library accordingly
const dllPath = path.join(__dirname, 'libfb-lib.so');
// Load the shared library
const libf = ffi.Library(dllPath, {
'fb_screen': ['bool', ['int']],
'fb_console': ['bool', []],
'fb_print': ['bool', ['string']],
'fb_sleep': ['bool', ['int']],
'fb_cls': ['bool',[]],
});
// Call the 'fb_console' function
const result = libf.fb_console();
if (result) {
libf.fb_cls();
// Call the 'fb_print' function with a wide string
const myString = "Hello from FreeBASIC";
const myWideString = iconv.encode(myString, 'utf32-le');
const resultPrint = libf.fb_print(myWideString);
} else {
console.error("Printing failed");
}
// Sleep for 5000 milliseconds
const sleepResult = libf.fb_sleep(5000);