Results 1 to 4 of 4

Thread: Dynamically loadable modules in Lianja 6.

  1. #1
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,246

    Dynamically loadable modules in Lianja 6.

    One of the weaknesses of LianjaScript/VFP is lack of module support.

    In Lianja 6 dynamically loadable modules are now supported.

    This provides OO encapsulation for existing code so that loading a library does not "pollute" the namespace and create potential problems due to name clashes.

    Use the require() function to dynamically load a library and reference its public variables and procedures/functions in an OO manner.

    The filename specified as the argument to the require() function must exist in the Lianja path or be prefixed with a special prefix e.g lib:/ or thirdpartylibs:/

    See screen shot below.

    Name:  Screen Shot 2021-03-06 at 9.48.10 AM.jpg
Views: 92
Size:  43.8 KB
    Last edited by barrymavin; 2021-03-06 at 00:52.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  2. #2
    Senior Member
    Join Date
    Oct 2012
    Posts
    209


  3. #3
    Lianja MVP
    Join Date
    Feb 2012
    Location
    Berea, KY, USA
    Posts
    2,071
    Great stuff. The memvar encapsulation as properties will be especially useful, essentially turning global vars at the top level into properties.

  4. #4
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,246
    Note also that JavaScript in Lianja also supports dynamically loadable modules.

    The require( cExpression ) function loads the JavaScript library module file specified in cExpression and returns back the module.exports object. This is used in a similar way to node.js require().

    Code:
    var utils = require("./utils");
    
    // where ./utils.js contains:
    
    var myfunc = function() {
        // myfunc code
    };
    var myfunc2 = function() {
        // myfunc2 code
    };
    module.exports.myvar = "hello world";
    module.exports.myfunc = myfunc;
    module.exports.myfunc2 = myfunc2;
    This works in desktop and web apps.

    Modules are useful!
    Last edited by barrymavin; 2021-03-06 at 21:51.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us