I'm using luajit2.0.4 as lua interpreter. here is the situation:
after I load a dynamic lib like cjson.so with
cjson = require('cjson')
a=cjson.new() -- blahblah... do things i want
then I need to overwrite the lib file, ( a situation of hot upgrade, and here cjson.so_1 and cjson.so might be the same)
[root@localhost lib]# cp cjson.so_1 cjson.so
cp: overwrite `cjson.so'? y
it will force kernel to truncate the physical memory of cjson.so's pmap, and causing a page missing then when I call
a=cjson.new()
again, the kernel will recopy the cjson.so lib into memory, this time not parsing the global symbols. so when I call new() which need to call external functions like malloc(), a segment fault will occur.
I've already found a way to reload by writing a unload funtion in C,
and my question is can I do this by lua code itself?
Sadly, this is not possible.
You'd have to approach the situation using C/C++, but not using Lua, due to the way in which Lua works, and I wish there would've been a different answer but Lua has got it's limits.