Reusable code in custom libraries?

As a programmer I am used to writing class libraries with utilities that can be reused across the application. Is there any way I can do this for MiOS / Vera?
For instance, can I write a function called CompareTime(time1, time2) in luup and use it from several scenes / events?
Could anything similar be achieved another way?

Thanks

You can put Lua libraries in /usr/lib/lua and require() them in the code that needs to use them.

Thanks @futzle, it works on my windows test platform. To anyone else interested, here is where I got started:
[url=http://lua-users.org/wiki/LuaModuleExample]http://lua-users.org/wiki/LuaModuleExample[/url]

How would I go about compiling it for Vera? Is there a cross-compiler that can make the .so file, or should I transfer the source file and compile it on Vera?

Thanks

Oh, they are shared-object Lua libraries and not pure-source Lua libraries?

You will need a cross-compiler to build them for the Vera platform. I haven’t done this, but I know what’s involved. Download the OpenWrt source, compile a firmware image, and then use the included cross-compiler to build your Lua .so files. Then cross your fingers.

Now I see :slight_smile: The simple solution was of course to put the mylib.lua file in /usr/lib/lua and use require(“mylib”).

What I read was to write a C module and put the compiled library there. It’s a different level of difficulty for sure! Most days I’m a Windows guy and I know that compiling a distro usually requires many late hours. I think I will go with the simple scripting solution for now and see how far that will take me :slight_smile:

Thanks for the help!