Note that there are some explanatory texts on larger screens.

plurals
  1. POLuaLanes Unable to pass global variables between functions (in a single lane)
    primarykey
    data
    text
    <p>hope you're having a good day.</p> <p>I have been programming a IRC chatbot in Lua the past few days, and finally I want to start implementing multiple server support into it.</p> <p>So far, I have created the irc "object" to manage each server, and all that happy stuff - Now, I am having problems with threading. </p> <p>Lua, as you probably know, doesn't have thread support built-in. LuaLanes and LuaThreads seemed like the closest to what I wanted to use, in terms of libraries. What made me choose LuaLanes is because LuaThreads requires a modified lua core. Plus the "lindas" feature of LuaLanes caught my eye (for later use in plugins)</p> <p>Anyway, the issue that I'm having is when you generate a lane using function <code>middleman</code> (for example), which then calls another function <code>sqr</code> (for example). if you generate the function like <code>lanes.gen({globals = _G}, middleman)</code>, middleman will have access to everything in your current global scope, which is exactly what I want. The problem is, if <code>middleman</code> calls <code>sqr</code>, and <code>sqr</code> uses something from the global scope, it throws an error, almost as if <code>_G</code> suddenly became empty.</p> <p>Here's some example code I managed to throw together, using my example above:</p> <pre><code>require 'lanes' function sqr() print(5*5) end function middleman() sqr() end gen = lanes.gen({globals = _G}, middleman) print(gen()[1]) </code></pre> <p>Produces an error saying:</p> <pre><code>tc@box:~$ lua lanestrouble.lua lua: lanestrouble.lua:4: attempt to call global 'print' (a nil value) stack traceback: [C]: in function 'error' ./lanes.lua:190: in function &lt;./lanes.lua:136&gt; lanestrouble.lua:13: in main chunk [C]: ? threading.c 399: pthread_cond_destroy(ref) failed, 16 EBUSY Aborted tc@box:~$ </code></pre> <p>(By the way, I'm using linux)</p> <p>However, if you change line 11 from <code>gen = lanes.gen({globals = _G}, middleman)</code> to <code>gen = lanes.gen({globals = _G}, sqr)</code>, it works fine.</p> <p>I've checked, and the same thing happens if you pass "*" (or any other option for the "libs_str" parameter) to load the default libraries.</p> <p>I really wish there was something like Java's threading library for Lua, that's how I originally learned to use threads. (I know, not the most ideal environment I suppose)</p> <p>Thanks, I appreciate help a lot. Especially since this has completely halted my IRC bot development! :(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload