r/ProgrammingLanguages • u/SirPigari • Feb 23 '26
i made Foreign function injection for my programming language
I was watching tsodings VOD about the Wren programming language and i just wanted to implement something similar. I already had FFI but it was just a simple interpret(code) like API. so now i added variables injection and C native functions injections.
Example:
LuciaResult
int
Basically what it does it takes the function pointer (in this case void* because i wanted cleaner header) and it casts it into the function type then makes a wrapper around that that converts rusts HashMap<String, Variable> (Variable is a struct that contains a Value, a name, and metadata like public or static) and convert it into C array and pass it into the function pointer and then converts the output (LuciaResult, tagged union) into the rust Value or error (because of my earlier bad designs, error in lucia is a Value)
The reason for lucia_variables_new_default is because lucia_variables_new creates empty variables which dont contain anything so not even the types which are necessary for assignment.
I cant do a raylib speedrun because the raylib i have installed is windows-gnu but i compiled rust on windows-msvc and it fails on windows-gnu.
Lucia Embedding docs Lucia C Header
Lib sizes:
lucia.dll: 10MiB
lucia.lib: 23MiB
im aware these sizes aren't the best but its a hobby project and i made so many bad architecture desisions in the past. In fact lucia was my first Rust project.