Skip to content

ams:exec()

Captain Spaulding edited this page Oct 6, 2021 · 30 revisions

DESCRIPTION

This method creates a task, which will run a given function, and inserts it in the kernel queue, handled by the kernel main process. It returns the pointer to the task object created and the task's ID number in the queue.

SYNTAX

<task>, <taks_ID> = ams:exec(<function_to_call>, <description>, [<loop_queue>], [<opt_arg>])

PARAMETERS

  • <funtion_to_call> - the pointer to the function that will be called at each iteration;
  • <description> - a string containing the name that will appear in the status informations;
  • [<loop_queue>] - optional, the background loop where the task should be inserted, it defaults to ams.C.FRAME_LOOP; (see ams.C)
  • [<opt_arg>] - optional, custom arguments to be used in the function's body.

RETURNS

  • <task> - a pointer to the task object; (see core.class.task)
  • <task_ID> - the task unique identification number.

REQUIRES

  • require('ams')

TASK OBJECT METHODS

type description
<task>:exec() method Executes the function (typically used by the kernel scheduler)
<task>:kill() method Kill it self
<task>:pause() method Pauses the task indefinitively
<task>:resume() method Resumes the execution once paused
<task>:hi_priority() method Sets the process as 'hi-priority'
<task>:low_priority() method Sets the process as 'low-priority'
<task>:set_queue(queue) method Move the process to the given queue (see kernel constants)
<task>:set_arg(el) method Sets the arg variable to
<task>.arg variable Holds any kind of user value or array

EXAMPLES

require('ams')

local function my_funct(self)
	print("Hello world.")
	self:kill()		--> kills itself
end

local my_task = ams:exec(my_funct, "My Test Function")
require('ams')

local function my_funct(self)
	print("Hello world.")
	self:kill()		--> kills itself
end

local function repetitive_task(self)
	ams:exec(my_funct, "My Test Function", ams.C.OFTEN_LOOP)	--> every second
end

ams:exec(repetitive_task, "My Neverending Loop", ams.C.SOMETIMES_LOOP)	--> every 10 second
require('ams')

local function my_counter(self)
	if self.parm == 0 then
		print("Let's Start.")
	elseif self.parm == 10 then
		print("Ten.")
	elseif self.parm == 20 then
		print("Twenty.")
	elseif self.parm > 30 then
		self.kill()
	end
	self.parm = self.parm + 1
end

ams:exec(my_counter, "My Counter is counting...", ams.C.OFTEN_LOOP, 0)
require('ams')

local function slave_process(self)
	print("Hello World!")
end

local function master_process(self)
	if self.parm.count == 10 then
		self.parm.slave:pause()
	elseif self.parm.count == 20 then
		self.parm.slave:resume()
	elseif self.parm.count > 30 then
		self.parm.slave:kill()
		self:kill()
	end
	self.parm.count = self.parm.count + 1
end

local slave = ams:exec(slave_process, "Slave process", ams.C.FRAME_LOOP)
local master = ams:exec(master_process, "Master process", ams.C.OFTEN_LOOP, {count = 0, slave = slave})

ams.core

ams.sys

  • ams.sys.info
  • ams.sys.timer
  • ams.sys.win.timer

ams.SDK

  • ams.SDK.XPML
  • ams.SDK.scenery
  • ams.SDK.map
  • ams.SDK.datarefs
  • ams.SDK.AIplanes
  • ams.SDK.menus
  • ams.SDK.processing
  • ams.SDK.graphics

ams.carillon

  • ams.carillon.carillon

ams.utils

  • ams.utils.tts

ams.install

  • ams.install.loader

ams.ext

kickstarter

AMS Scripts

Clone this wiki locally