This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Execution of a resident script
#1
Hello,

Is it possible for a resident script to be executed from a file that is uploaded to a device and not be visible in the window of the LM?
Reply
#2
You can use a user library with "Keep source" disabled.
Reply
#3
Can you give me some details?
How do I activate it? Can I change it if I need to?
Sorry for the stupid questions!
Reply
#4
See page 39: https://openrb.com/wp-content/uploads/20...3.2022.pdf

User library example:
Code:
return function()
-- your code here
end

Resident script example (change my_user_library to your user library name):
Code:
fn = require('user.my_user_library')
fn()
Reply
#5
Thank you so much!
Am I to understand that if I have the library saved, make changes and set it to the same name, it will overwrite the original library? Is this code backed up with the project?
Reply
#6
Without "Keep source" only the compiled bytecode library is saved. The editor will be empty in this case because the source is not kept. You can put new code there and it will overwrite the current library. The backup will include such library but without the source code of course.
Reply
#7
This is exactly what I needed.
Do I have to write this code (fn = require('user.my_user_library')fn()) in a resident script to call the library?
Reply
#8
Yes, this code is needed. It can also be shortened like this:
Code:
require('user.my_user_library')()
Reply
#9
I couldn't do something. Can you give a concrete example of how to put this sample code into a library, running as a resident script with 0 sleep time?
Code:
if not pirs then
  pirs = {
    { input = '1/1/1', output = '2/1/1' },
    { input = '1/1/2', output = '2/1/2' },
  }
end

now = os.time()
for _, pir in ipairs(pirs) do
  key = 'pir_timer_' .. pir.input
  delta = now - storage.get(key, 0)

  -- set output to 0% after 1 hour
  if delta > 60 * 60 then
    grp.checkwrite(pir.output, 0)
  -- set output to 20% after 30 minutes
  elseif delta > 30 * 60 then
    grp.checkwrite(pir.output, 20)
  end
Reply
#10
An example. I created user library with name 'test'

This is the library:
Code:
return function()
log('test')
end


Each time it is called it will create log 'test'

To cal it create a resident or any other script and use this code.

Code:
fn = require('user.test')
fn()
------------------------------
Ctrl+F5
Reply
#11
Thanks a lot, now I understand how it works.
Reply


Forum Jump: