Equivalent of classes in LiveCode

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

aetaylorBUSBnWt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 54
Joined: Thu Sep 20, 2012 5:11 pm

Re: Equivalent of classes in LiveCode

Post by aetaylorBUSBnWt » Thu Sep 03, 2020 9:34 pm

Hi,

I just checked out Mark's updated OOPEngine from gitHub.
I opened the OOPEngine.livecode file and for the first time, opened the Card Scripts.
I found out why there are newClass and deleteClass scripts.

Below is the openStack handler for that card.

Apparently there was the expectation of storing class script files down in the plugins folder.
Are these supposed to be .livecodescript text files? With the way the code is written, the file name must be the class name, which means no extension on the file name.

Was this a potential mechanism for people to distribute classes?

Seems interesting to have, but if one puts one's classes down there, does the LiveCode "create a standalone application file" process know to collect up those files?

Code: Select all

on openStack
   local tPath, tFiles
   local tFolder
   local tNewObjectID
   local tScript
   
   put the defaultFolder into tFolder
   start using this stack
   put revEnvironmentUserPluginsPath() into tPath
   put "/Classes" after tPath
   if there is a folder tPath then
      set the defaultFolder to tPath
      put the files into tFiles
      push card
      go card "Classes"
      repeat for each line tFile in tFiles
         put newClass(tFile) into tNewObjectID
         put url ("file:" & tPath & "/" & tFile) into tScript
         set the script of control id tNewObjectID to tScript
      end repeat
      pop card
      set the defaultFolder to tFolder
   end if
end openStack

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3202
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Equivalent of classes in LiveCode

Post by mwieder » Thu Sep 03, 2020 11:27 pm

Oh. Sorry - I meant to get rid of that code.
Yeah, that was an attempt at a repository for class text files, and then I realized that it would work in the IDE but not for standalones.
The need for that openStack handler has been deprecated in favor of Brian's registerClass/registerClasses handlers.

bwmilby
Posts: 354
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Equivalent of classes in LiveCode

Post by bwmilby » Fri Sep 04, 2020 7:54 pm

The compare on GitHub isn't working like I would expect it to. Here's a current view of the differences between my copy of the main stack script of the OOPEngine and Mark's (created with DeltaWalker). The first difference is the removal of the extra handlers that are commented out (83-148 in Mark's). The second change is in the implementation of newObject (Changes start at 149, 198-263 deleted from Mark's). The private function classExists? is not used, so it could go away (since it is private, the once or twice where that comparison is used it could be swapped out for the function call without much effect).

This weekend I'll get Particles updated. I think it is better leaving the Emitter class as a sub-stack so that the project is more self contained while still demonstrating how to use a stack as a class.
Attachments
OOPEngineDiff.html.zip
(7.3 KiB) Downloaded 34 times
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3202
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Equivalent of classes in LiveCode

Post by mwieder » Fri Sep 04, 2020 8:24 pm

Thanks. I don't see any substantive differences in the two forms, just stylistic differences.
Obviously mine is better :P
Good call on the ability now to remove the classExists? function - I only used it in the newClass handler, and now that's been deprecated.

As far as future-proofing, I see I'm only passing a single argument to constructors, and I'm wondering if it's necessary to flesh that out and pass more as necessary.

aetaylorBUSBnWt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 54
Joined: Thu Sep 20, 2012 5:11 pm

Re: Equivalent of classes in LiveCode

Post by aetaylorBUSBnWt » Fri Sep 04, 2020 8:45 pm

Looking better to me with every iteration.

Once we have opened Pandora's Box allowing for parameters to a class constructor, yes one has to allow for an unknown number.
Fortunately that code is simple and little impact if there are no extra parameters.

An example of extraction code for the constructor to extract the parameters should be included in the example constructor command.

I like the idea of the Emitter class being a substack to show off options.

aetaylorBUSBnWt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 54
Joined: Thu Sep 20, 2012 5:11 pm

Re: Equivalent of classes in LiveCode

Post by aetaylorBUSBnWt » Fri Sep 18, 2020 12:43 pm

Hi,

Has there been any updates since Sept 4?

Another question: I am looking at the processes of using this and trying to figure the best way to implement classes and group them so that they are convenient to use. Since many have absolutely no UI, it seems that a subStack per class makes sense.

Normally I have 1 class per file.
It seems that LiveCode is really structured to only have 1 file open at a time, with all the code and UI contained in that single file.
This does NOT promote use of code in multiple projects.

What is the best way to get everything open at once (similar to an XCode project), yet not have to constantly copy modifications of code out to other files to be available for use in other projects?

If a class has any UI, the situation is more murky to me. In that case the class would likely be a button or similar object. It would not want its own Card or Stack. Independent of the class concept, how does one share the item and code with another project?

Thanks,
Andrew

bwmilby
Posts: 354
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Equivalent of classes in LiveCode

Post by bwmilby » Fri Sep 18, 2020 1:49 pm

ScriptOnly stacks are the way to go for shared code. Much of the IDE is implemented that way. In your project you will just need to be sure are all referenced in the Stack files tab of the stack properties. Having many files open is not an issue for LC but many projects can be self contained in a single stack.

All changes are in the GitHub repository. No real substantial changes. Mark’s code and mine are both updated to remove some of the excess code. I reordered the switch statement to make it easier to compare versions.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3202
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Equivalent of classes in LiveCode

Post by mwieder » Fri Sep 18, 2020 4:47 pm

Yes to script-only stacks as the way to go for sharing classes.
And you can promote them to substacks when creating a standalone app.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”