dibyendumajumdar / ravi

Ravi is a dialect of Lua, featuring limited optional static typing, JIT and AOT compilers
http://ravilang.github.io/
Other
1.16k stars 60 forks source link

question on using aot mode when lua file has multiple funtions? #252

Closed taotao6666 closed 1 year ago

taotao6666 commented 1 year ago

the lua file is as bellow, i dont know how to call function sieve2 when lib was loaded by load_ravi_lib

local modulex = {};

function modulex.sieve() local meta = {__index = function() end} for iter=0,100000 do local flags = {} setmetatable(flags,meta); for i=0,8190 do flags[i] = 1 end end return 1899; end

function modulex.sieve2() local meta = {__index = function() end} for iter=0,100000 do local flags = {} setmetatable(flags,meta); for i=0,8190 do flags[i] = 1 end end return 1888; end

return modulex;

dibyendumajumdar commented 1 year ago

hi @taotao6666 - I will try it and get back

dibyendumajumdar commented 1 year ago

Here is my test

local m = {}
function m.foo()
        print 'foo'
end
function m.bar()
        print 'bar'
end
return m

I saved this to a file and created shared lib. then

local chunk = package.load_ravi_lib('test_lib.so', 'mymain')
assert(chunk and type(chunk) == 'function')

local m = chunk()
m.foo()
m.bar()

So thing to remember is that the compiled code in shared library is a function created out of the Lua "chunk". You have to execute this function to get the table.

Having said this not sure what you are trying to do with your example code, as it seems bad for performance with Ravi.

taotao6666 commented 1 year ago

i get why it does not worked. when lua file modified ravi or lua vm must be restarted before aot

dibyendumajumdar commented 1 year ago

okay I assume then your issue is resolved.