Can node act as function, I can invoke it and pass parameters and return result?

52 views
Skip to first unread message

gufe...@gmail.com

unread,
Aug 18, 2016, 8:39:15 AM8/18/16
to leo-editor
If I write add a node name "@function say_hi( name)", node content like "retun "Hi " + name + " !" ", I can invoke it like below:

@funcion say_hi("zenkoo"), finally the text is "Hi zenkoo!". If leo has this feature, that is very cool.

Edward K. Ream

unread,
Aug 18, 2016, 9:03:01 AM8/18/16
to leo-editor
On Thu, Aug 18, 2016 at 6:44 AM, <gufe...@gmail.com> wrote:
If I write add a node name "@function say_hi( name)", node content like "ret
​​
u
​r​
n "Hi " + name + " !" ", I can invoke it like below:

@func
​t​
ion say_hi("zenkoo"), finally the text is "Hi zenkoo!". If leo has this feature, that is very cool.

​Thanks for this question.  It's interesting.​ Afaik, there is nothing exactly like this in Leo.

First, let me warn you that certain solutions might have serious security consequences.  For example, you could define functions in nodes using @script. It doesn't seem well documented, but @script is a security concern, and so is disabled by default.

Second, scripts may define code that can be used later as follows:

    exec(g.findTestScript(c,'my_commands'))
    << code that uses my_commands >>

Again, this could be a security concern because this script is executing unknown code (the code in the node whose headline is "my_commands").

In general, however, it is not necessary to do what you are asking, for several reasons:

1. Typically, code of whatever kind (plugins, modules, scripts) can use Python's import command to import common code.

2. For complex Leo scripts, I recommend a top-level that looks something like this:

   << imports >>
   @others # defines Controller class in subtree
   x = Controller(c)
   x.run()

This is a simple, flexible, powerful pattern that can be used to define huge scripts.

In short, your question is interesting, but I'm not aware of any real reason to want to do what you are asking.  Feel free to ask more questions.

Edward

Terry Brown

unread,
Aug 18, 2016, 9:59:06 AM8/18/16
to leo-e...@googlegroups.com
You could take a look at the valuespace plug in, it can construct node content from pieces elsewhere in the outline.
Cheers -Terry

gufe...@gmail.com

unread,
Aug 22, 2016, 11:18:48 PM8/22/16
to leo-e...@googlegroups.com
Think you for reply! It is my first post at google group, as I am not good at english.

 I am a embedded programer, use C language as  major language. I maintain about 30+ projects, most of them is similar, just has little different. Some time that diffrents is hard to use C marco to handle it . So I ask that question, if I can use Leo node as function and generate that differents part, it is perfect. It seem like Leo act as writing DSL, and other format document is the output. That is what I real to want. If node can as as function, and can invoke it at the same leo document, I can use template technology and other technology to generate document segment and insert to where I want it to.

Thinks again, for your reply!

在 2016年8月18日星期四 UTC+8下午9:03:01,Edward K. Ream写道:

gufe...@gmail.com

unread,
Aug 22, 2016, 11:21:25 PM8/22/16
to leo-editor
Thank you! I will try it.

在 2016年8月18日星期四 UTC+8下午9:59:06,Terry Brown写道:
Reply all
Reply to author
Forward
0 new messages