LiveCodeServer stack ---> .lc file. How to? ( ^..^)?

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
Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

LiveCodeServer stack ---> .lc file. How to? ( ^..^)?

Post by Mariasole » Mon Jul 18, 2016 11:41 am

Hello everyone!

I am studying in my submarine, the technique that Richard had suggested to me long ago* and I was intrigued.

It is probably a trivial thing, but this is the beginners forum, right? :D

The technique uses a stack on the server as "library" in favor of a .lc file.

I did some tests, but do not understand much. Let me give an example.

1) I build the stack that is called wow.livecode

Code: Select all

function Summy
   put 1 + 1 into tSummy
end Summy
2) I build the page .lc called summy.lc

Code: Select all

<!doctype html>
<html>
  <head>
    <title>Summy</title>
  </head>
  <body>
<?lc
put tSummy
?>
  </body>
</html> 
Obviously it does not work! :oops:
I do not understand how to tell to summy.lc that tSummy function is inside the wow stack!

I know, I do not understand anything! But I have so much good will ...
Could someone help me?

Thank you all!
Mariasole
( ^..^)ノ



* [Richard: "But you can keep code in stack files that can be called from .lc files..."] http://forums.livecode.com/viewtopic.ph ... 17#p139749
Last edited by Mariasole on Mon Jul 18, 2016 2:38 pm, edited 1 time in total.
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Communication problems (LCS stack/.lc file) ||| ( ^..^)

Post by MaxV » Mon Jul 18, 2016 2:37 pm

First your summy is wrong, this is the correct one:

########CODE#######
function Summy
put 1 + 1 into tSummy
return tSummy
end Summy
#####END OF CODE#####

then you must use start using form to load summy function

Code: Select all

<!doctype html>
<html>
  <head>
    <title>Summy</title>
  </head>
  <body>
    <?lc
        start using stack "wow.livecode"
         put Summy()
     ?>
  </body>
</html> 
Read also here: http://lessons.livecode.com/s/lessons/m ... de-Server-
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: LiveCodeServer stack ---> .lc file. How to? ( ^..^)?

Post by Mariasole » Mon Jul 18, 2016 6:09 pm

Thank you MaxV,
Your help was crucial :D .

I also read parts of the manual that you have given me, but I do not understand well yet.

I learned to call a function, but as I recall the text that is not produced by a function?
For example, if I create a header.lc files and I write:

Code: Select all

put header "Content-Type: text/html; charset=utf-8" 
I can recall in my .lc page simply so:

Code: Select all


<?lc include "header.lc" ?>

<!doctype html>
<html>
  <head>
    <title>Summy</title>
  </head>
  <body>
<p>hello</p>
  </body>
</html> 

How do I do the same thing with the stack?




Thanks so much!
Mariasole
( ^..^)ノ
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: LiveCodeServer stack ---> .lc file. How to? ( ^..^)?

Post by MaxV » Tue Jul 19, 2016 12:58 pm

Livecode have the following type procedures:
  • functions
  • messages
  • setProp
  • getProp
Function
it returns a value (qualunque cosa, testo, numero, ecc.). It must be used within a statement, like a value. So this is correct:
########CODE#######
on myFunc temp
return (temp + 2)
end myFunc

on mouseUp
put myFunc(5) into temp2
answer temp2
end mouseUp
#####END OF CODE#####

Message
It doesn't return anythig, so all must happen in itself.
########CODE#######
on myMessag temp
answer (temp + 2)
end myMessag

on mouseUp
myMessag 5
end mouseUp
#####END OF CODE#####

SetPropt & GetProp
like messages, but they are automatically activated when setting o retrivieng a property.
########CODE#######
setProp myCustomProperty newValue
set myCustomProperty of me to newValue
answer "You changed myCustomProperty to " & newValue
end myCustomProperty

getProp myCustomProperty
answer "You wanted to know the value of myCustomProperty"
return the myCustomProperty of me
end myCustomProperty

on mouseUp
set the myCustomproperty of me to 5
get the myCustomproperty of me
put it into temp
end mouseUp
#####END OF CODE#####

On normal livecode use for software, you use cards or answer/ask to display anything to the user.
On server mode, you use put. Put in the IDE output to the message box, in server it output to the server page content.

Now you can create a wow.livecode with this:
########CODE#######
on OpenStack
put header "Content-Type: text/html; charset=utf-8"
end OpenStack

function Summy
put 1 + 1 into tSummy
return tSummy
end Summy
#####END OF CODE#####

and a web page with:

Code: Select all

<?lc 
 start using stack "wow.livecode"
?>
<!doctype html>
<html>
  <head>
    <title>Summy</title>
  </head>
  <body>
    <?lc 
         put Summy()
     ?>
  </body>
</html> 
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: LiveCodeServer stack ---> .lc file. How to? ( ^..^)?

Post by Mariasole » Tue Jul 19, 2016 1:55 pm

Thank you very much MaxV !
Grazie davvero per la completezza della tua risposta! :D
Now I fill my page with these functions and commands!
Also I think you've made a very useful thing for us beginners.
Do I still thanks, on behalf of all those like me, who are learning, especially LCS.
But there is a problem in your script: the header does not work!
I did a test.

Here is a "classic" file .lc that contains all the elements:

Code: Select all

<?lc
   put header "Content-Type: text/html; charset=utf-8"
   put header "TRY: bla bla bla"
   put header "Cache-Control: max-age=1000"
?>

<!doctype html>
<html>
  <head>
    <title>Header</title>
  </head>
  <body>
<p>hello</p>
  </body>
  </html> 

The header of the page, controlled with several online tools, it confirms the presence of:

TRY bla bla bla
Cache-Control max-age=1000
Content-Type text/html; charset=utf-8


The instructions for the header have been successfully transmitted! :D

------------------------------------------------------------------------------


This rather the version "on the stack":



this is the stack wow.livecode
:

Code: Select all

on OpenStack
   put header "Content-Type: text/html; charset=utf-8"
   put header "TRY: bla bla bla"
   put header "Cache-Control: max-age=1000"
end OpenStack
This is the test page:

Code: Select all


<?lc
start using stack "wow.livecode"
?>
<!doctype html>
<html>
  <head>
    <title>Header</title>
  </head>
  <body>
<p>Hello!</p>
  </body>
</html>

This time the tools that control the header tell me:

Content-Type text/html; charset=iso-8859-1

No trace of: :cry:
TRY bla bla bla
Cache-Control max-age=1000

The "Content-Type text/html; charset=iso-8859-1 " is the sign that the header was not generated at all, given that unfortunately "iso-8859-1" is the default signature of LCS. :evil:

Where am I wrong? :?:

Grazie ancora, grazie a tutti!
Mariasole
( ^..^)ノ
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: LiveCodeServer stack ---> .lc file. How to? ( ^..^)?

Post by MaxV » Wed Jul 20, 2016 9:57 am

Try this, change wow.livecode to this:
########CODE#######
on LibraryStack
put header "Content-Type: text/html; charset=utf-8"
end LibraryStack

function Summy
put 1 + 1 into tSummy
return tSummy
end Summy
#####END OF CODE#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Mariasole
Posts: 235
Joined: Tue May 07, 2013 9:38 pm

Re: LiveCodeServer stack ---> .lc file. How to? ( ^..^)?

Post by Mariasole » Thu Jul 21, 2016 12:33 pm

Grazie MaxV!
Now it seems that everything works perfectly, I will continue to do tests and let you know! :D
Thanks so much!

Mariasole
( ^..^)ノ
"I'm back" - The Cyberdyne Systems Model 101 Series 800 Terminator

Post Reply