Skip to content
This repository has been archived by the owner on Jan 4, 2018. It is now read-only.
/ memory.lua Public archive

A simple way to keep track of objects in lua. Not only can each object destroy itself. Also all objects can be freed and cleaned at the same time. This is done with one line of code. Memory keeps track of the objects itself. This means an entire set of objects can be cleaned from an entirely separate file or location without knowing anything abo…

Notifications You must be signed in to change notification settings

lanceulmer/memory.lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

memory.lua

A simple way to keep track of objects in lua. Not only can each object destroy itself. Also all objects can be freed and cleaned at the same time. This is done with one line of code. Memory keeps track of the objects itself. This means an entire set of objects can be cleaned from an entirely separate file or location without knowing anything about the objects that are being cleaned.

Functions

The following functions are included in memory:

  • memory.add(object) -- Add one object to memory. This object must have a clean function to work properly with memory.
  • memory.remove(object) -- Remove one object from memory. This calls the object's clean function.
  • memory.kill() -- This runs the clean function on all remaining objects and removes them from memory.

Installation

Drop memory.lua into your project and load it with:

local memory = require("memory")

Usage

The best way to learn about memory is the attached coronaSDK project. Each "particle" can be tapped to clean it by itself. Also, the clean button can remove all of the "particles" at the same time.

Here is a basic example:

-- load memory
local memory = require("memory")

-- add an object with a clean() function
local object1 = {}
object1.clean = function()
  print("clean")
end

memory.add(object1)

-- clean the object from memory
memory.remove(object1)


-- add another object
local object2 = {}
object2.clean = function()
  print("clean")
end

memory.add(object2)

-- clean all objects from memory
memory.kill()

Note

memory.lua was written in moonscript. The source code can be found in the "src" folder.

About

A simple way to keep track of objects in lua. Not only can each object destroy itself. Also all objects can be freed and cleaned at the same time. This is done with one line of code. Memory keeps track of the objects itself. This means an entire set of objects can be cleaned from an entirely separate file or location without knowing anything abo…

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages