Logic Machine Forum
Lua - require only a part of library - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Lua - require only a part of library (/showthread.php?tid=1535)



Lua - require only a part of library - buuuudzik - 14.08.2018

Is there such possibility like in NODE JS?


Code:
const {calcDistance} = geoFunctions;

I think this could be a nice feature.


RE: Lua - require only a part of library - Erwin van der Zwart - 14.08.2018

Hi,

You can always create a new lib with part of functions you need..

I don’t see any added value to this only when you have huge libs with lots of functions that would be loaded, creating several user libs has the same result...

Next to that i have never seen huge user libs up to now..

BR,

Erwin


RE: Lua - require only a part of library - buuuudzik - 14.08.2018

(14.08.2018, 07:11)Erwin van der Zwart Wrote: Hi,

You can always create a new lib with part of functions you need..

I don’t see any added value to this only when you have huge libs with lots of functions that would be loaded, creating several user libs has the same result...

Next to that i have never seen huge user libs up to now..

BR,

Erwin

Yes I know but in NODE JS this is normal. And current direction is to use only what necessary and not unnecessarily import something.

Added value is I think in performance(maybe a little but it is, and LM is a little CPU so optimization is important). Another advantage is that you can declare above your code what variables and functions you are use from the library. This would be especially useful with Common functions.


RE: Lua - require only a part of library - Erwin van der Zwart - 14.08.2018

Hi,

I don’t think a couple of KB’s will be realy noticed by the CPU.. 

When it’s called by a event it will be unloaded after the event so it’s only temperary load.

Also i would never use common functions for special functions, only when functions are needed by the majority of the scripts i would put it there, otherwise it’s always better to require them when needed.

Even the default functions in common functions should by moved to a user lib if you ask me, sunset calc or mail are not used by the majority of the scripts but loaded by every script, if you worry about unneeded load i would start there (:

I see your point but splitting your functions by several user libs or putting the function direct in your script is just as effective..

BR,

Erwin


RE: Lua - require only a part of library - buuuudzik - 15.08.2018

Yes, I am optimizing Common functions and also normally I'm not using auto load libraries. Post was more induced by inspiration of JS environment and it's modern featuresWink

Nice to see your opinion ErwinWink