lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello! I needed an annotation library, for annotations. So I made an annotation library. It's called Annotation^, or APow.

Repo: https://bitbucket.org/TeamSoni/apow

Features:

- Uses itself to define the annotation annotation (kinda).
- Simple API.
- Adds annotations.
- All rights reserved.
- Tiny. Less than 512 bytes.

To use it, just require "apow".annotation ^ function(self, target) [your annotation handler here] end.

For example, here's a simple module that defines a notnil annotation:

- - -
local apow = require "apow"

local notnil = apow.annotation ^ function(self, target)
  if target == nil then
    error("value must not be nil")
  end
  return target
end

return {notnil = notnil}
- - -

Which can then be used as follows:

- - -
local notnil = require "notnil".notnil

local function f(x)
  x = notnil ^ x
end

assert(pcall(f, 1))
assert(not pcall(f, nil))
- - -

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.