Library in LiveCode

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Library in LiveCode

Post by cbarbal » Wed Nov 14, 2018 4:25 pm

Hi all,

In the YouTube Livecode channel there is the video: Learn to Code: A Local Database with Michael McCreary that uses the libDB.livecodescript library

I have a few questions:

A library is created as a normal stack and then the livecode extension is changed by livecodescript?

It is always an individual stack on the same level as the application or it can be a substack. If so, what is better?

If the ID connection is in the library, can I use it from the mainStack? In principle queve that a local variable of the stack of the library

From the library, you could make a similar query to this. If you know how to do it :D

Code: Select all

SELECT finca Property, d.anyo Year,  l.Income , d.Expenses
FROM Finques f
LEFT JOIN (
	SELECT fincaID, anyo ,  sum(total) Expenses
	FROM Despeses
	GROUP BY fincaID, anyo) d
	ON f.fincaID = d.fincaID AND l.anyo = d.anyo
LEFT JOIN (
	SELECT fincaID, anyo, sum(total) Income
	FROM Lloguers
	GROUP BY fincaID, anyo ) l
	ON l.fincaID = f.fincaID AND l.anyo = d.anyo
I hope Google's translation is understood.

Carles

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Library in LiveCode

Post by jacque » Fri Nov 16, 2018 9:16 pm

There are two types of library stacks.

A library can be a normal stack, separate from your mainstack. When it is put in use ("start using stack xxx") the stack script is inserted as a backscript. The extension on the stack file is usually .livecode. These stacks can contain other resources, like images or custom properties, but only the stack script is inserted into the message path. The resources in the stack can be accessed or used for storage, and will be saved whenever the stack is saved to disk.

Another type of library is a "script-only stack" with extension .livecodescript. This type of library is just a text file on disk. When it is put in use, LC creates a temporary stack in RAM and inserts the script from the text file into the message path as a backscript, the same way a regular stack library does. But when saved to disk, only the stack script is saved in the text file. This means you cannot save any other resources to the stack, they will be lost when the library is closed.

Both types of libraries are usually individual files on disk, apart from your main stack. But you can store a regular library stack as a substack instead if you want.

If your database ID is a global variable, you can use it from anywhere during the current session. Or you can pass the ID to the handlers in the library so you don't need a global variable. Or it is more common to store the ID in a script-local variable in the library script and keep all the database commands in the same script.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm

Re: Library in LiveCode

Post by capellan » Fri Nov 16, 2018 11:45 pm

Hi Jacque,
jacque wrote:
Fri Nov 16, 2018 9:16 pm
[snip]

Another type of library is a "script-only stack" with extension .livecodescript. This type of library is just a text file on disk. When it is put in use, LC creates a temporary stack in RAM and inserts the script from the text file into the message path as a backscript, the same way a regular stack library does. But when saved to disk, only the stack script is saved in the text file. This means you cannot save any other resources to the stack, they will be lost when the library is closed.

[snip]

Could we compress and encrypt these script only stacks?

Al

cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Re: Library in LiveCode

Post by cbarbal » Sat Nov 17, 2018 4:42 pm

Hi Jacque,

Thanks for the information. When I consider myself qualified to do it, I know I have two options.

Regards,

Carles

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Library in LiveCode

Post by jacque » Sat Nov 17, 2018 5:06 pm

Could we compress and encrypt these script only stacks?
For storage maybe, but I think the engine needs a text file to actually use it. You'd need to decrypt and decompress the file before putting it in use.

The main reason script-only stacks were introduced was for compatibility with versioning systems like git, which don't work well with binary files. If you aren't planning to use a versioning system then you'll get more options with a regular stack, including the ability to save the library as a substack in the mainstack.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Library in LiveCode

Post by Mikey » Sat Nov 17, 2018 6:06 pm

Levure will let you encrypt your SOS's. In your development environment, your SOS's are just SOS's. When you build your app, Levure will convert your SOS's to binary stacks and compile them. Your app won't know the difference.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”