1 - Im known what package.loadlib lowlevel call
2 - Im known what package.loadlib OS depend call
I have 2 cases for package.loadlib first case just for fun
Im have 2 C modules for example
A.c -> A.so
B.c -> B.so
But Im need one AB.so with two (or more!) modules inside one library
thanks package.loadlib I can do it
Make module functions and structs as static and build
gcc -c moda.c `pkg-config --libs --cflags lua5.4` -o liba.o
gcc -c modb.c `pkg-config --libs --cflags lua5.4` -o libb.o
gcc liba.o libb.o -shared -o A.so
Now just local and call functions from two modules from single library
print(package.loadlib("./A.so","luaopen_A")().fromc_a());
print(package.loadlib("./A.so","luaopen_B")().fromc_a());
Awesome, thanks for package.loadlib!
Next another way for example I need call C function from libname.so
without compile It with Lua API.
For now its realy posible, aka pseudo FFI =)
NOTICE DO NOT DO THAT!!!!!!!!!!!! HTIS IS HACK THIS IS BAD!!!! THIS BROKE C STACK BROKE!!! JUST FUN EXAMPLE!! IF YOU LAUNCH THIS THE EARTH WILL STOP AND THE MOON WILL FALL ON YOUR FLOWER BEDS, NOOOOOOOOO :D
print(package.loadlib("/lib/x86_64-linux-gnu/libc.so.6","puts")("hello"));
But it works :) Okey this is bad, this is hack, but I can compile just C library without
Lua API, just for call C function without communicate with Lua, just call as lua_CFunction, and and that's all, never more.
for example
#include <stdio.h>
int example_func(void * empty) /* This void* for no break C stack for place Lua state*/
{
...
very_very_hard_c_working /*some hard work inside func*/
...
printf("Work done\n"); /*just notice*/
return 0; /*send to Lua CFunc_call no values return*/
}
Now build it
gcc mod.c -shared -o mod.so
Now call it
print(package.loadlib("./mod.so","example_func")());
My question is, since the function example_func as a whole is designed correctly from the point of view lua_CFunction this is my NoLuaAPI C NotModule correct or not? :D
Or is it the same stupidity as the broken stack in the example above for directly puts call?
There are just cases when I don't need to exchange data between languages, I just need to call functions.
That's all from me :) Lua cool hehe