Promixis, LLC Forums  

Go Back   Promixis, LLC Forums > Girder > Girder 4

Reply
 
Thread Tools Display Modes
  #11  
Old November 8th, 2006, 05:48 PM
dsmes dsmes is offline
Senior Member
Experienced User
 
Join Date: Jun 2005
Posts: 730
Default

Should even simple functions be added as a method? e.g. I have a function that calculates the modified Julian day that doesn't need to be passed any data. But should I pass it the data table anyway so it can write the result there?
Code:
MJD = function(self, data)
   local tm = {}
   tm = os.date('*t')
   self.MJD = 367 * tm.year - math.floor(7 * (tm.year + math.floor((tm.month + 9) / 12)) / 4)
         + math.floor(275 * tm.month / 9) + tm.day + 1721013.5 - 2400000.5
end,
BTW, glad someone remembers punched cards (our kids will think Lua is just as primative). Were you ever exposed to teletype "ticker-tape"?
Reply With Quote
  #12  
Old November 9th, 2006, 02:50 AM
Rob H's Avatar
Rob H Rob H is offline
Senior Member
Promixis Team
 
Join Date: May 2004
Location: Cardigan, UK
Posts: 9,278
Default

I'd probably not put that in the class - it's more of a utility function and should just return the result. Either make it a local function in the same file (before the class definition), or put it in a separate file and use require to load that file.

I used to own a Friden Flexowriter back in the late 70s
__________________
--Rob

Last edited by Rob H; November 9th, 2006 at 02:53 AM.
Reply With Quote
  #13  
Old November 9th, 2006, 06:29 AM
dsmes dsmes is offline
Senior Member
Experienced User
 
Join Date: Jun 2005
Posts: 730
Default

Why "before the class definition"? I know a function has to be defined before it's called, but doesn't that happen at G startup before any serial data is received?
Reply With Quote
  #14  
Old November 9th, 2006, 06:34 AM
Rob H's Avatar
Rob H Rob H is offline
Senior Member
Promixis Team
 
Join Date: May 2004
Location: Cardigan, UK
Posts: 9,278
Default

Because I suggested making it a local function ie

Code:
local function MJD()
That way you avoid polluting the global namespace. But for anything declared as local it must be defined before it is used because of the Lua scoping rules.
__________________
--Rob
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 08:41 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright (c) Promixis, LLC