Is there any known workaround for using external call with non-libc functions?

I know that it's possible with libc, but I haven't figured out a way to use other C libraries.
5 Replies
ms
ms2y ago
you can use ffi.DLHandle like dlopen, then use get_function with the fn signature as the type parameter
🥀Azazelle🥀
🥀Azazelle🥀OP2y ago
Ah, you mean like this?
from sys import ffi

def main():
let handle = ffi.DLHandle("math.h")
let cos = handle.get_function[fn(FloatLiteral) -> FloatLiteral]("cos")
print(cos(0.5))
from sys import ffi

def main():
let handle = ffi.DLHandle("math.h")
let cos = handle.get_function[fn(FloatLiteral) -> FloatLiteral]("cos")
print(cos(0.5))
ModularBot
ModularBot2y ago
Congrats @🥀Azazelle🥀, you just advanced to level 2!
ms
ms2y ago
no that stuff isn't built yet. you have to specify the shared library. it works like dlopen/dlsym
🥀Azazelle🥀
🥀Azazelle🥀OP2y ago
Yeah, thanks for the reply, and apologies for my former dumbassery

Did you find this page helpful?