1

I've been racking my brain at this all day and I just cannot figure it out. My server uses a single state that loads all of my scripts in as global variables (for calling any time without having to luaL_dofile each time I want to run a script). The problem comes in when I attempt to use lanes. require "lanes" works as it should (I think? It returns a table to package.loaded appropriately...) since I have the lanes.lua in the appropriate directory on Linux (Ubuntu 11.10 x86). However, when I go to do lanes.gen("", functionName) it tells me... attempt to index global 'lanes': a nil value. At this point I decided to try package.loaded["lanes"].gen("", functionName) and it tells me... attempt to index field 'gen': a nil value If you need more information, please let me know. Thank you in advance for at least trying to help.

1 Answers1

1

If you are using the latest LuaLanes (which is what you get by luarocks install lanes), the supported way of loading the module is this:

local lanes = require "lanes".configure()

configure() will create all the necessary functions, before calling configure() the module table is empty, which seems like your issue.

Michal Kottman
  • 16,375
  • 3
  • 47
  • 62
  • Okay, this does work. I do have a follow up though... I'm not terribly well versed with this lanes stuff, just trying to make use of its "not locking the main thread" which causes my server to hang. How can I get a thread created via `lanes.gen()` to communicate with C? Do I need to make a Linda object or something? Anyways, much appreciated on getting me this far. Hope you can handle this follow up as well. – user1332555 Apr 14 '12 at 15:58
  • Yes, in order to communicate between threads, you need a linda object. Create a `local linda = lanes.linda()` before the thread function to have it as an upvalue, and then use `linda:send()` and `linda:receive()` to communicate. – Michal Kottman Apr 15 '12 at 10:27
  • You were asking about how to make the created lane communicate with C (not with another lane, as @MichalKottman took it). You will need to make a C-side Lua module, just as you would without any multithreading. Please give more info (is it your own C stuff, or you just need to load in an existing module - use require). – akauppi Jul 12 '12 at 01:15