Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Urgently needed: global functions in lua


3JL

Recommended Posts

1 minute ago, jgab said:

Sidelining rights... well, we keep firearms away from children so they shouldn't hurt themselves - or others ;)  

best here! 

 

2 minutes ago, jgab said:

But that's just like a 'require'

 

if something is "green" and sometimes say "croak-croak"... Look, I mean, it doesn't even have to be a frog... :)

Jan, Fibaro guys prevent accessing to fs. maybe it's right. also IMHO he prevents accessing to some core low-level LUA functions.

require('\opt\fibaro\scripts\remote-support.lua')

:)

but you are right 

ok let is be  'require('sceneID')

12 minutes ago, jgab said:

All the fibaro mgmt of scenes (starting, stopping, triggers etc) need to make exceptions for "library scenes" -

yes.

A6mfhiqEfR.png

 

Link to comment
Share on other sites

7 minutes ago, 10der said:

best here! 

 

 

if something is "green" and sometimes say "croak-croak"... Look, I mean, it doesn't even have to be a frog... :)

Jan, Fibaro guys prevent accessing to fs. maybe it's right. also IMHO he prevents accessing to some core low-level LUA functions.

require('\opt\fibaro\scripts\remote-support.lua')

:)

but you are right 

ok let is be  'require('sceneID')

yes.

A6mfhiqEfR.png

 

 

Nice picture. But why would a library need all the confusing (non-functioning) scene options in the GUI? Why not a separate tab for libraries? I guess one would like to reference libraries by names and not IDs as they are not stable (you never now what ID you get when you add/remove/add scenes)

Anyway, I'm not sure we help the poor developer at Fibaro thinking about global functions by just discussing the syntax. There are still all the other considerations I listed in the first post.

...when to load, performance, security, versioning, bloat, support...

I would love to have 'loadstring()' and would check "I voluntary void my HC2 warranty [X]", but I'm not sure others wanting to use my libraries would also do it... or trust me.

Link to comment
Share on other sites

cuz what I can propose Fibaro (IMHO) can implement for one sprint.

but if we asking Fibaro "separated tab with Blackjack and Hookers ..." we're going to grow old before Fibaro implement this feature.

Link to comment
Share on other sites

9 minutes ago, 10der said:

cuz what I can propose Fibaro (IMHO) can implement for one sprint.

but if we asking Fibaro "separated tab with Blackjack and Hookers ..." we're going to grow old before Fibaro implement this feature.

Yes, but I think the last thing we need to do is to encourage Fibaro to make the HC2 less trusted :-) 

 

Link to comment
Share on other sites

So, my point is that a "petition" for global functions ("straight forward implemented") is like a petition for opening up the HC2... and then people should be aware of that.

A compromise, seen in other Lua sandboxes (games etc) is to have a few approved libraries available for require()... and I guess they could be "precompiled"... 

Link to comment
Share on other sites

2 minutes ago, jgab said:

So, my point is that a "petition" for global functions ("straight forward implemented") is like a petition for opening up the HC2... and then people should be aware of that.

sorry. it's not clear for me?

we can't be asking fibaro allow to use require but we asking to able to use own scenes / scripts.

Jan, please, do not  puts its own spin on the facts.

Link to comment
Share on other sites

9 minutes ago, 10der said:

sorry. it's not clear for me?

we can't be asking fibaro allow to use require but we asking to able to use own scenes / scripts.

Jan, please, do not  puts its own spin on the facts.

I'm not spinning anything. Please read up on how 'require' is implemented. Scenes are sandboxed by Fibaro - 'require' execute its code in the global environment - access to os.execute and whatever other stuff that Fibaro doesn't want us to thinker with.

Anyone can imagine pigs flying but it's damn hard to make them do it in reality...

Link to comment
Share on other sites

1 minute ago, jgab said:

I'm not spinning anything. Please read up on how 'require' is implemented. Scenes are sandboxed by Fibaro - 'require' execute its code in the global environment - access to os.execute and whatever other stuff that Fibaro doesn't want us to thinker with.

Anyone can imagine pigs flying but it's damn hard to make them do it in reality...

ORLY?

 

\opt\fibaro\FibaroSceneEnv.lua 

Please login or register to see this code.

 

There's nothing that prohibits Fibaro devs likewise disable context all prohibits functions in the include file.

and if Fibaro will implement implicitly require  via the header as I said before: is the lesser evil.

9 minutes ago, jgab said:

pigs flying

 

I have opened a bottle of beer and turn on Pink Floyd 

Happy Friday. Sir!

Link to comment
Share on other sites

So how would you implement it via the header? Most likely with something like ‘require’ which is inherently unsafe. You can set the environment afterwards but that is too late as ‘require’, ‘loadstring’ etc always use the global environment while compiling and loading no matter what you have set _G to. Any code can execute while it’s loading. No other Lua sandboxed environment out there, games platforms etc,  allows ‘require’ (except for in some cases approved libs).

Please read up on how Lua implements it and we can have a more constructive discussion, and try to come up with a real solution.

When I saw people starting “petitions”without understanding the underlying issues (and no one from Fibaro explaining the issues), I just wanted to explain that it’s not that straight forward... 

Link to comment
Share on other sites

Jan! I am really want to say thank you for your libs, sharing knowledge etc...

but.... That's where you're wrong. Fibaro uses native C++ libs Luabind 

Please login or register to see this link.

 for implementing scenas and VD's. Devs can include any files on low-level without publishing some methods.

yes it's my IMHO. Sorry, but I'm out.

Ok! you win.

 

  • Thanks 1
Link to comment
Share on other sites

??

...anyway, I didn't say that 'require' was used to load scenes/VDs. Luabind is to start the scene environment - and you see that they themselves use 'require' to pull in mqtt and netHTTClient - and there is a good reason for that. Note that even though _G is filtered afterwards, mqtt and net* doesn't crash when they are later used because 'require' always have the full environment effectively making the loaded libs running outside the sandbox. Loading multiple lua files with luabind and luaL_loadfile into the same Lua state without conflicts is messy and is why 'require' and its semantic is used. Yes, anyone that has hacked their HC2 can add any file but that was not what the discussion was about. The point was to find a safe, resource efficient, and easy approach. Hack together an acceptable luabind example loading multiple files that share environment and propose it to Fibaro....

Just realising that we run 5.2 now (I was still in 5.1 land) I'm leaning towards a rewritten 'require' using Lua's load(ld [, source [, mode [, env]]]) that seems to be able to load with a sandbox environment. Still worried about precompiling and versioning and efficiency though... Still see sandboxed platforms out there (game platforms etc) only allowing loading pre-provided lua libraries. I guess most common useful lua libraries out there will not work in a sandbox anyway... but this was for users' own code so that may not matter.

Link to comment
Share on other sites

  • 5 weeks later...

Just checked the FS content

/opt/fibaro/FibaroSceneAPI.lua - is the common interface file. Its passed to every lua scene process as a parameter (as much as FibaroSceneEnv.lua). I guess its the best place to store common functions for all scenes.

IMHO Would be cool to make some "github" with commonly used functions to keep some "standart" here

 

HC2 - just to append the file in rootfs

HCL - need to link the file to user_data partition in order to make it writeble (r/o rootfs)

Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...