1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
-- tolua: define class
-- Written by Waldemar Celes
-- TeCGraf/PUC-Rio
-- Jul 1998
-- $Id: define.lua,v 1.2 2001/11/26 23:00:23 darkgod Exp $
-- This code is free software; you can redistribute it and/or modify it.
-- The software provided hereunder is on an "as is" basis, and
-- the author has no obligation to provide maintenance, support, updates,
-- enhancements, or modifications.
-- Define class
-- Represents a numeric const definition
-- The following filds are stored:
-- name = constant name
classDefine = {
name = '',
_base = classFeature,
}
settag(classDefine,tolua_tag)
-- register define
function classDefine:register ()
local p = self:inmodule()
if p then
output(' tolua_constant(tolua_S,"'..p..'","'..self.lname..'",'..self.name..');')
else
output(' tolua_constant(tolua_S,NULL,"'..self.lname..'",'..self.name..');')
end
end
-- unregister define
function classDefine:unregister ()
if not self:inmodule() then
output(' lua_pushnil(tolua_S); lua_setglobal(tolua_S,"'..self.lname..'");')
end
end
-- Print method
function classDefine:print (ident,close)
print(ident.."Define{")
print(ident.." name = '"..self.name.."',")
print(ident.." lname = '"..self.lname.."',")
print(ident.."}"..close)
end
-- Internal constructor
function _Define (t)
t._base = classDefine
settag(t,tolua_tag)
if t.name == '' then
error("#invalid define")
end
append(t)
return t
end
-- Constructor
-- Expects a string representing the constant name
function Define (n)
local t = split(n,'@')
return _Define {
name = t[1],
lname = t[2] or t[1]
}
end
|