From 38bb61c648eae7a6e31224c425fef55823e7328e Mon Sep 17 00:00:00 2001 From: Mauro Iazzi Date: Tue, 11 Nov 2008 15:10:01 +0100 Subject: [PATCH] do not create the same functions every time --- generator/classes.lua | 196 +++++++++++++++++++++++++------------------------- 1 file changed, 99 insertions(+), 97 deletions(-) rewrite generator/classes.lua (85%) diff --git a/generator/classes.lua b/generator/classes.lua dissimilarity index 85% index 4e6e97b..6f32ad0 100644 --- a/generator/classes.lua +++ b/generator/classes.lua @@ -1,97 +1,99 @@ -#!/usr/bin/lua - -lqt = lqt or {} -lqt.classes = lqt.classes or {} - -lqt.classes.insert = function(cname, types) --, cancopy) - local pointer_t = function(fn) - return { - -- the argument is a pointer to class - push = function(n) - return 'lqtL_passudata(L, '..n..', "'..fn..'*")', 1 - end, - get = function(n) - return 'static_cast<'..fn..'*>' - ..'(lqtL_toudata(L, '..n..', "'..fn..'*"))', 1 - end, - test = function(n) - return 'lqtL_isudata(L, '..n..', "'..fn..'*")', 1 - end, - } - end - local pointer_const_t = function(fn) - return { - -- the argument is a pointer to constant class instance - push = function(n) - return 'lqtL_passudata(L, '..n..', "'..fn..'*")', 1 - end, - get = function(n) - return 'static_cast<'..fn..'*>' - ..'(lqtL_toudata(L, '..n..', "'..fn..'*"))', 1 - end, - test = function(n) - return 'lqtL_isudata(L, '..n..', "'..fn..'*")', 1 - end, - } - end - local ref_t = function(fn) - return { - -- the argument is a reference to class - push = function(n) - return 'lqtL_passudata(L, &'..n..', "'..fn..'*")', 1 - end, - get = function(n) - return '*static_cast<'..fn..'*>' - ..'(lqtL_toudata(L, '..n..', "'..fn..'*"))', 1 - end, - test = function(n) - return 'lqtL_isudata(L, '..n..', "'..fn..'*")', 1 - end, - } - end - local instance_t = function(fn) - return { - -- the argument is the class itself - push = function(n) - return 'lqtL_copyudata(L, &'..n..', "'..fn..'*")', 1 - end, - get = function(n) - return '*static_cast<'..fn..'*>' - ..'(lqtL_toudata(L, '..n..', "'..fn..'*"))', 1 - end, - test = function(n) - return 'lqtL_isudata(L, '..n..', "'..fn..'*")', 1 - end, - } - end - local const_ref_t = function(fn) - return { - -- the argument is a pointer to class - push = function(n) - return 'lqtL_copyudata(L, &'..n..', "'..fn..'*")', 1, string.gsub(fn, ' const&$', '') - end, - get = function(n) - return '*static_cast<'..fn..'*>' - ..'(lqtL_toudata(L, '..n..', "'..fn..'*"))', 1 - end, - test = function(n) - return 'lqtL_isudata(L, '..n..', "'..fn..'*")', 1 - end, - } - end - if types[cname]==nil then - types[cname..'*'] = pointer_t(cname) - types[cname..' const*'] = pointer_const_t(cname) - types[cname..'&'] = ref_t(cname) - --if cancopy then - types[cname] = instance_t(cname) - types[cname..' const&'] = const_ref_t(cname) - --end - return true - else - return false - end -end - - - +#!/usr/bin/lua + +lqt = lqt or {} +lqt.classes = lqt.classes or {} + + +local pointer_t = function(fn) + return { + -- the argument is a pointer to class + push = function(n) + return 'lqtL_passudata(L, '..n..', "'..fn..'*")', 1 + end, + get = function(n) + return 'static_cast<'..fn..'*>' + ..'(lqtL_toudata(L, '..n..', "'..fn..'*"))', 1 + end, + test = function(n) + return 'lqtL_isudata(L, '..n..', "'..fn..'*")', 1 + end, + } +end +local pointer_const_t = function(fn) + return { + -- the argument is a pointer to constant class instance + push = function(n) + return 'lqtL_passudata(L, '..n..', "'..fn..'*")', 1 + end, + get = function(n) + return 'static_cast<'..fn..'*>' + ..'(lqtL_toudata(L, '..n..', "'..fn..'*"))', 1 + end, + test = function(n) + return 'lqtL_isudata(L, '..n..', "'..fn..'*")', 1 + end, + } +end +local ref_t = function(fn) + return { + -- the argument is a reference to class + push = function(n) + return 'lqtL_passudata(L, &'..n..', "'..fn..'*")', 1 + end, + get = function(n) + return '*static_cast<'..fn..'*>' + ..'(lqtL_toudata(L, '..n..', "'..fn..'*"))', 1 + end, + test = function(n) + return 'lqtL_isudata(L, '..n..', "'..fn..'*")', 1 + end, + } +end +local instance_t = function(fn) + return { + -- the argument is the class itself + push = function(n) + return 'lqtL_copyudata(L, &'..n..', "'..fn..'*")', 1 + end, + get = function(n) + return '*static_cast<'..fn..'*>' + ..'(lqtL_toudata(L, '..n..', "'..fn..'*"))', 1 + end, + test = function(n) + return 'lqtL_isudata(L, '..n..', "'..fn..'*")', 1 + end, + } +end +local const_ref_t = function(fn) + return { + -- the argument is a pointer to class + push = function(n) + return 'lqtL_copyudata(L, &'..n..', "'..fn..'*")', 1, string.gsub(fn, ' const&$', '') + end, + get = function(n) + return '*static_cast<'..fn..'*>' + ..'(lqtL_toudata(L, '..n..', "'..fn..'*"))', 1 + end, + test = function(n) + return 'lqtL_isudata(L, '..n..', "'..fn..'*")', 1 + end, + } +end + +lqt.classes.insert = function(cname, types) --, cancopy) + if types[cname]==nil then + types[cname..'*'] = pointer_t(cname) + types[cname..' const*'] = pointer_const_t(cname) + types[cname..'&'] = ref_t(cname) + --if cancopy then + types[cname] = instance_t(cname) + types[cname..' const&'] = const_ref_t(cname) + --end + return true + else + return false + end +end + + + -- 2.11.4.GIT