LuaLanes / lanes

Lanes is a lightweight, native, lazy evaluating multithreading library for Lua 5.1 to 5.4.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

VaasKahnGrim opened this issue · comments

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
  2. TestLanes - gamemodes/vaasrp/gamemode/core/security_sv.lua:221
    3. unknown - lua_run:1

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

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

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

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
  2. include - [C]:-1
    3. unknown - gamemodes/vaasrp/gamemode/shared.lua:123
    4. include - [C]:-1
    5. unknown - gamemodes/vaasrp/gamemode/init.lua:22

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

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.

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/

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!!

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