Detecting if a file is running in the main thread, or a different thread

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Guard13007
Party member
Posts: 132
Joined: Sat Oct 25, 2014 3:42 am
Location: Internet, USA
Contact:

Detecting if a file is running in the main thread, or a different thread

Post by Guard13007 »

I'm working on an update to my version checking library which will make using it more like a standard module by requiring it and calling functions on the returned table (instead of its current behavior, which is to be loaded into a thread and called, then check a channel for its result). I would like to maintain compatibility with the old usage, so I want the module to detect if it is being loaded in a thread other than the main thread and respond differently in that case.

My solution for now is by checking if love.graphics or love.window is defined, as those are only accessible on the main thread. However, someone who has disabled these inside their conf.lua file will negate this attempt to check.

Is there any definite way to check from Lua code if it is running in the main thread or another thread?
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Detecting if a file is running in the main thread, or a different thread

Post by grump »

Code: Select all

local isthread = arg == nil
Global arg is only defined in the main thread, not in other threads.
User avatar
Guard13007
Party member
Posts: 132
Joined: Sat Oct 25, 2014 3:42 am
Location: Internet, USA
Contact:

Re: Detecting if a file is running in the main thread, or a different thread

Post by Guard13007 »

Thank you very much! :D
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 118 guests