LuaLanes / lanes

Lanes is a lightweight, native, lazy evaluating multithreading library for Lua 5.1 to 5.4.
Other
465 stars 96 forks source link

Having some issues with getting things working right, no real useful examples that show usage clearly #187

Closed VaasKahnGrim closed 2 years ago

VaasKahnGrim commented 4 years ago

Basically I'm attempting to use LuaLanes inside a gamemode I've been working. I currently have this portion of code setup attempting to test it out but I'm running into some issues. I'm 99% sure that my first problem is I'm not using the right thing to achieve what I want, unfortunately the doccumentation doesn't make it clear what I need.

Theres also not exactly any usage tutorials out there to go off of and learn to use the thing. Not beyond simple math stuff like return (2+5)*5, which is pretty much a useless example for something like multi-threading imo. Doesn't really make it clear on how to "USE" this thing properly.

Anyways to my issue and the code I'm currently working with. My goal is to make various functions that will be able to run at the same time via as other instances of itself are also running. However I can't get past the part of figuring out what I'm doing wrong here in order to know how to even get to my goal:

require("lanes") --Load the LuaLanes module
lanes.configure()

--Create our two lanes
local e_func = lanes.gen(function(n)
    for i=1,n do
        print("Thead E is running")
    end
end)

local f_func = lanes.gen(function(n)
    for i=1,n do
        print("Thead F is running")
    end
end)

--Start up the lanes?
function TestLanes()
    e_func(1000)
    f_func(1000)
end

The error I end up getting however is this:

[ERROR] main: function 'print' not found in Lane #0x271f01c0 destination transfer database.

  1. e_func - [C]:-1
    1. TestLanes - gamemodes/vaasrp/gamemode/core/security_sv.lua:221
    2. unknown - lua_run:1
sonoro1234 commented 4 years ago

local e_func = lanes.gen("*", function(n)

VaasKahnGrim commented 4 years ago

doing the "*" just seems to cause an instant crash for me

sonoro1234 commented 4 years ago

Running your script says: attempt to index global 'lanes' (a nil value)

Try running:

local lanes = require("lanes") --Load the LuaLanes module
lanes.configure()

--Create our two generators of lanes
local e_func = lanes.gen("*",function(n)
    for i=1,n do
        print("Thead E is running")
    end
end)

local f_func = lanes.gen("*",function(n)
    for i=1,n do
        print("Thead F is running")
    end
end)

--Start up the lanes?
function TestLanes()
        --Create our two lanes
    local E = e_func(1000)
    local F = f_func(1000)
        --join the lanes
    print(E[1],F[1])
end

TestLanes()

Shouldn't crash

VaasKahnGrim commented 4 years ago

adding the local lanes = before require results in this happening:

[ERROR] gamemodes/vaasrp/gamemode/core/security_sv.lua:201: attempt to index local 'lanes' (a nil value)

  1. unknown - gamemodes/vaasrp/gamemode/core/security_sv.lua:201
    1. include - [C]:-1
    2. unknown - gamemodes/vaasrp/gamemode/shared.lua:123
      1. include - [C]:-1
      2. unknown - gamemodes/vaasrp/gamemode/init.lua:22

Removing it resolves the issue there but I still end up with the crashing happening.

sonoro1234 commented 4 years ago

It seems you have a quite unusual setup (security_sv, shared, init). You should try first with any standard setup. You should be able to run any of the scripts in test folder also.

VaasKahnGrim commented 4 years ago

Not all that possible really, Garry's mod already loads alot of other lua files by default so I can't exactly get it where its just my script running on its own.

But basically init.lua includes shared.lua and then shared.lua includes several other files to create a load order for various features of the gamemode, security_sv.lua being one of those sections of the gamemode that get loaded.

But even if none of thats being loaded, theres still the default lua folder and base gamemode that always get loaded first. I can't really change that since I don't have source code access to the c/c++ side of game.

All I have is basically just this and then using it in my gamemode: https://github.com/danielga/gmod_lanes/

sonoro1234 commented 4 years ago

All I have is basically just this and then using it in my gamemode: https://github.com/danielga/gmod_lanes/

Then you should ask there!!

VaasKahnGrim commented 4 years ago

its just a direct port from here, thats why I came here lol. but I'll give there a shot again I guess XD