Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua Lanes: attempt to index global 'os' (a nil value)

Tags:

lua

I wanted to use Lua Lanes to do a multithreading and record the time taken. Here is the code:

require "lanes"

function performTest ()
    os.execute("testJson-mt.lua")
end

for i=1,10,1 do
    f= lanes.gen(performTest)
    a=f()
    startTime = os.time()
    print("ID "..a[1].." completed.")
    endTime = os.time()
    diff = os.difftime (endTime, startTime)
    print(i..","..os.date("%x %X",startTime)..","..os.date("%x %X",endTime)..","..startTime..","..endTime..","..diff)
end

However, when I run the code, the console returns an error: lua: testLanes.lua:4: attempt to index global 'os' (a nil value).

This error code point to this line where os.execute("testJson-mt.lua"). I don't quite understand this error. Please advise.

Note: I am using Lua for Windows as the IDE.

like image 415
ktlim Avatar asked May 09 '12 09:05

ktlim


1 Answers

By default, lanes.gen loads no libraries, not even base libraries. Therefore pass '*' as the first parameter to lanes.gen to get the os and other modules in the lane.

like image 123
Michal Kottman Avatar answered Oct 13 '22 14:10

Michal Kottman