View RSS Feed

LianjaDev

HOWTO use loadable modules in LianjaScript

Rate this Entry
LianjaScript Modules are similar to libraries in that they can be dynamically loaded and contain procedures that may be used in your Apps.

Modules however encapsulate all procedures, functions and public variables and make these only visible from an object. This prevents name clashes and is a simple way to wrap code libraries into objects without any special coding syntax.

Modules provide simple (Object-Oriented Programming ) OOP concepts:

  • Objects
  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism

e.g.

Code:
// file: mylib1.prg
public myvar = “Barry”

proc getMyVar()
return myvar
You dynamically load a module using the require() built-in function

Code:
public mylib = require(“mylib1”)
You can now access the public variables and call procs like this.

Code:
value = mylib.myvar
value = mylib.getMyVar()
Modules also handle inheritance

Code:
// file: mylib2.prg
public myvar = “Bill”

proc getMyVar()
return myvar
Now dynamically load the modules

Code:
public mylib = require(“mylib1”, “mylib2”) // , “mylib3”… etc
You can now access the public variables and call procs like this.

Code:
value = mylib.myvar
value = mylib.getMyVar()
Modules can optionally contain an init() initialization proc which is called after the module is loaded.

Code:
// file: mylib3
public myvar = “Bill”

proc init()
    myvar = “Tom”
endproc

proc getMyVar()
return myvar
Note that the filenames specified as arguments to the require() function may contain the special filename prefixes such as lib:/ and thirdparytlibs:/ etc

Lianja also supports JavaScript dynamically loadable modules in both desktop and web apps. This will be covered in another article.

Prerequisites

Lianja 6.3

Submit "HOWTO use loadable modules in LianjaScript" to Google Submit "HOWTO use loadable modules in LianjaScript" to Facebook Submit "HOWTO use loadable modules in LianjaScript" to Twitter

Updated 2022-01-04 at 03:35 by barrymavin

Tags: None Add / Edit Tags
Categories
LianjaDev , LowCode , ProCode , HOWTO

Comments

  1. HankFay's Avatar
    Fantastic, Barry. This simplifies complex programming in the right way.
Journey into the Cloud
Join us