Bílý vrch
icon TrekBuddy
www.trekbuddy.net
Outdoor companion.
  • internal / bluetooth / simulator GPS
  • offline raster maps
  • smart GPX / raw NMEA logs
  • waypoints and simple navigation
  • custom views
  • MIDP and Symbian phones
  • Blackberry
  • Android
Visit wiki to see all features, guides and howtos. Project tracker.
Trekbuddy is on Github now

Partners:    (Polish/Polski)(Polski) Compass mapy      (Polish/Polski)(Polski) Galileos mapy      (Polish/Polski)(Polski) CartoMedia      (Czech/Èesky)(Èesky) Eaglesoft trasy      (Polish/Polski)(Polski) ExpressMap     

 FAQFAQ   SearchSearch   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Using global variables of a plug-in in a CMS?

 
Post new topic   Reply to topic    TrekBuddy Forum Index -> Themes
View previous topic :: View next topic  
Author Message
JNT



Joined: 10 Jan 2009
Posts: 415
Location: Sweden

PostPosted: Tue Jan 19, 2016 8:57 pm    Post subject: Using global variables of a plug-in in a CMS? Reply with quote

Is it possible to use global variables defined in a plug-in in a CMS?

If I define a global variable, say, sail::var1 in live.sail.hcl, can I then use it in sail.hcl?

I want to use them as user-setable variables.
Back to top
View user's profile Send private message
kruch
Site Admin


Joined: 02 Jul 2006
Posts: 5673

PostPosted: Tue Jan 19, 2016 11:14 pm    Post subject: Reply with quote

I think so, there is only one instance of Hecl interpreter at runtime, all variables defined outside functions ('proc') exist in the same name/address space...
Back to top
View user's profile Send private message
JNT



Joined: 10 Jan 2009
Posts: 415
Location: Sweden

PostPosted: Wed Jan 20, 2016 7:24 am    Post subject: Reply with quote

OK, sounds good. I will test and report my success or problems.
Back to top
View user's profile Send private message
JNT



Joined: 10 Jan 2009
Posts: 415
Location: Sweden

PostPosted: Wed Jan 20, 2016 5:22 pm    Post subject: Reply with quote

Unfortunately this does not work for me. Hopefully I'm doing something wrong...

I took an existing plugin example (live.time.hcl)
I enabled it (green dot next to it)
In it the variable time::sound is defined as 7 (can be changed in settings)
I tried to display this variable in my CMS (<value>time var: {$time::sound}</value>)
I only get "time var: ?"

I also (in my hcl file) tried to assign $time::sound to one of my own variables, but it did not work.

So, any suggestions?
Back to top
View user's profile Send private message
kruch
Site Admin


Joined: 02 Jul 2006
Posts: 5673

PostPosted: Wed Jan 20, 2016 11:05 pm    Post subject: Reply with quote

There is a bug, will fix it.
Back to top
View user's profile Send private message
kruch
Site Admin


Joined: 02 Jul 2006
Posts: 5673

PostPosted: Fri Jan 22, 2016 11:59 am    Post subject: Reply with quote

Fixed in http://www.trekbuddy.net/dev/2016-01-22/trekbuddy.apk.

!You can access variables from CMS in a plugin, but not vice versa . For your use-case (great idea, btw Smile), it should be enough, if not let me know.
Back to top
View user's profile Send private message
JNT



Joined: 10 Jan 2009
Posts: 415
Location: Sweden

PostPosted: Fri Jan 22, 2016 12:20 pm    Post subject: Reply with quote

kruch wrote:
You can access variables from CMS in a plugin, but not vice versa . For your use-case (great idea, btw Smile), it should be enough, if not let me know.


Oh, thanks, but maybe then unfortunately it was not such a great idea, since I want vice versa... I want to have set-able variables that I can use in my CMS.
Back to top
View user's profile Send private message
kruch
Site Admin


Joined: 02 Jul 2006
Posts: 5673

PostPosted: Fri Jan 22, 2016 1:50 pm    Post subject: Reply with quote

My understanding of your idea was:

Declare variable(s) in CMS, and let user change them via plugin.

cms.test.xml:
Code:
...
<area x="0" y="0" w="320" h="20">
     <value>show something {$kruch::info}</value>
</area>

cms.vars.hcl:
Code:
...
var kruch::info "Hello"


Then, in plugin, you can let user to change kruch::info value

live.test.hcl:
Code:

proc test::getVersion {} {
    return 1.0
}

proc test::getName {} {
    return "My CMS configurator"
}

proc test::getStatus {} {
    return "OK"
}

proc test::getDetail {} {
    return "no detail"
}

proc test::getOptions {} {
    return [kruch::info]
}

proc test::getActions {} {
    return [list ]
}
Back to top
View user's profile Send private message
JNT



Joined: 10 Jan 2009
Posts: 415
Location: Sweden

PostPosted: Fri Jan 22, 2016 2:29 pm    Post subject: Reply with quote

kruch wrote:
My understanding of your idea was:

Declare variable(s) in CMS, and let user change them via plugin.


Absolutely brilliant! This way only the changing is done outside the CMS.
Much better. I was stuck thinking I have to declare them in the plugin to be able to change them in the plugin. And then only use them in the CMS.

Thanks! Much appreciated. Very Happy

Cant wait to test it this evening.
Back to top
View user's profile Send private message
JNT



Joined: 10 Jan 2009
Posts: 415
Location: Sweden

PostPosted: Fri Jan 22, 2016 9:08 pm    Post subject: Reply with quote

It works! Very Happy Very Happy
Back to top
View user's profile Send private message
JNT



Joined: 10 Jan 2009
Posts: 415
Location: Sweden

PostPosted: Sat Jan 23, 2016 11:53 am    Post subject: Reply with quote

Now I need to understand how things are initialised...

The plugin stores the values "permanently" somewhere, so when Trekbuddy is launched again, these values still exists. These values can be displayed with the xml files, but it seems the CMS hecl file does not know about them until something happens internally in the CMS to these variables. Little puzzling... Confused (but that is to be expected if using things outside their intended purpose)
Back to top
View user's profile Send private message
kruch
Site Admin


Joined: 02 Jul 2006
Posts: 5673

PostPosted: Sat Jan 23, 2016 2:28 pm    Post subject: Reply with quote

If you mean that CMS hcl file does not know about the changed values during initialization (ie. all code outside functions), then you are unfortunately right Sad
During TB startup, first CMS hcl are executed and then plugins hcl.

We have probably several ways how to fix it... For example:
* I make CMS hecl runtime have access to plugins HECL runtime
* same variables could be declared both in plugin and CMS
* plugins would be initialized first

So - if there was no plugin installed, CMS would use values specified in its own hcl declaration (var keyword), otherwise CMS declaration would be silently ignored and plugin value would be used.

HECL visiliblity CMS->plugin is ok for me. Maybe it makes even more sense than the current one Rolling Eyes
Back to top
View user's profile Send private message
JNT



Joined: 10 Jan 2009
Posts: 415
Location: Sweden

PostPosted: Sat Jan 23, 2016 3:39 pm    Post subject: Reply with quote

EDIT:
Just when I was starting to doubt my sanity... I found the reason why, irrespective of what I changed, it just behaved stranger and stranger...

Somehow there was an old copy of my CMS hcl file in the same folder...

So now I'm re-testing
Back to top
View user's profile Send private message
kruch
Site Admin


Joined: 02 Jul 2006
Posts: 5673

PostPosted: Sat Jan 23, 2016 8:05 pm    Post subject: Reply with quote

Should be fixed.

http://www.trekbuddy.net/dev/2016-01-23/trekbuddy.apk
Back to top
View user's profile Send private message
JNT



Joined: 10 Jan 2009
Posts: 415
Location: Sweden

PostPosted: Sat Jan 23, 2016 9:15 pm    Post subject: Reply with quote

Works completely as expected. Very Happy Brilliant!

Thanks a lot.

(I am convinced that most of my very strange behaviour was due to the extra hcl file in the same folder)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    TrekBuddy Forum Index -> Themes All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group