Hi,

I'm learning to use luatex these days, one day actually. It's very
interesting. Although reference manuals are available, I still don't
know how to implement my designation.

The thing is, I know there's a "self" variable for object-oriented
programming, like
==================================================================
\startluacode
testdata = { a = 0,
             b = 0,
             c = 0,
             plus = function (self)
                        self.c = self.a + self.b
                    end
           }
mytest = testdata
mytest.a=10
mytest.b=100
mytest:plus()
tex.print(mytest.c)
\stopluacode
==================================================================
OK, but what if I wanna do something more, like substract? I would
like to use another object, like
==================================================================
\startluacode
testdata = { a = 0,
             b = 0,
             c = 0,
             calc = Calc
           }
Calc     = { plus = function (self)
                        self.c = self.a + self.b
                    end,
             substract = function (self)
                        self.c = self.a - self.b
                    end
           }
mytest = testdata
mytest.a=10
mytest.b=100
mytest.calc:plus()
tex.print(mytest.c)
\stopluacode
==================================================================
Of course this won't work, for the "self" in Calc refers to mytest.calc
rather than mytest. How to implement things like that?

Thanks in advance.

-- 
Best Regards
Chen
----------------------------------------------------------------

          Zhi-chu Chen | Shanghai Synchrotron Radiation Facility
         No. 2019 | Jialuo Rd. | Jiading | Shanghai | P.R. China
             tel: 086 21 5955 3405 | zhichu.chen.googlepages.com
                                               | www.sinap.ac.cn
----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : [email protected] / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to