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
ms13mo ago
you can use ffi.DLHandle like dlopen, then use get_function with the fn signature as the type parameter
🥀Azazelle🥀
🥀Azazelle🥀OP13mo 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
ModularBot13mo ago
Congrats @🥀Azazelle🥀, you just advanced to level 2!
ms
ms13mo ago
no that stuff isn't built yet. you have to specify the shared library. it works like dlopen/dlsym
🥀Azazelle🥀
🥀Azazelle🥀OP13mo ago
Yeah, thanks for the reply, and apologies for my former dumbassery
Want results from more Discord servers?
Add your server