Anyone can share a working example on how to call a simple C# library (actually its WPF) from python code? (I have tried using IronPython and had too much trouble with unsupported CPython library my. When using graphql-tools, you define your field resolvers separately from the schema.Since the schema already describes all of the fields, arguments, and result types, the only thing left is a collection of functions that are called to actually execute these fields. Check our new training course. And Creative Commons CC-BY-SA. Lecture and lab materials. IPlugIn plugin = ModuleLoader.LoadModule(pluginId); In the next article, I will explain how you can use the ModuleLoader with an AppDomain to load and unload at runtime. 1 st April, 2008: Initial post.

  1. Moduleloader
  2. Module Loader Java
  3. Moduleload
ModuleLoader

Latitude libraries are normally organized into modules. Doing soprovides the user with convenient ways of loading your library andimporting specific names from it.

Script Files

As we’ve seen, Latitude scripts can be invoked from the command linelike so.

Latitude script files, by convention, end in .lats. A script filecan also be invoked from within a Latitude program or the REPL.

Kernel is a global singleton object that contains several methodsfor interacting with the Latitude VM at a relatively low level. ALatitude script is run like any other method in Latitude. It willreceive its own lexical and dynamic scopes1, and it will return thevalue of the final expression in the file.

Module Files

A module file is formatted slightly differently than a regular scriptfile in Latitude. For one thing, we use the extension .lat ratherthan .lats for Latitude modules. Second, Latitude modules mustalways have a header. The header of a module consists of linesbeginning with ;;* and containing information about the module.

Latitude package names use a reverse domain name scheme. The modulename should normally be the filename without the extension. If themodule is in a subfolder, then the module name should include forwardslashes / to indicate the path from the package’s root directory. Soif a file named foo.lat was located in the folder examples withinutil, an appropriate header might be

ModuleLoader

The Latitude standard library is separated into two portions: the corelibrary and the standard modules. The core library is the portion ofthe standard library which is imported into the Latitude VM atstartup, containing things like Kernel and Object. The standardmodules are a set of modules which are available for importing underthe package name '(latitude).

Module files are also loaded slightly differently. When a script fileis executed, it is run like a method and its final statement is itsreturn value. Modules behave similarly, but the module loadingmechanism expects that the return value be the module object itself.That is, modules should attach all of their functionality to a singleobject and return that object.

Latitude provides a newly-constructed module object to modules whichare loading by means of the $whereAmI variable2.While it is by no means required that you use this variable, there arebenefits to doing so, and it provides the user of your module with aconsistent, uniform import interface. As with many dynamic variables,it is often convenient to place the module object in anappropriately-named lexical variable. Thus, the usual structure of aLatitude module is

Importing Modules

Moduleloader

The simplest and most common way to import a module is with a usestatement.

This will define the name my-module in the current lexical scope.The value of that name will be the object returned from the modulefile, usually the module object. Thus, any methods or values attachedto the module object can now be accessed via the my-module object.

If you use a particular function frequently, you may import itexplicitly.

ModuleLoader

You may also import all names from the module, although this is notrecommended as it can very easily become confusing to determine whichnames came from which modules.

Module Loader Java

Modules can also be aliased with as. This, in particular, isespecially useful if you have a deeply nested module such as ourutil/examples/foo example earlier. It would be highly inconvenientto continue using the name util/examples/foo every time you need toreference the module.

Finally, it is always possible that the same module name could be inuse in multiple packages. In this case, you may explicitly qualify themodule with a package name.

Load Path

When a module is loaded with use or a similar form, the module’sname is looked up in the load path on the system. The load path isdetermined at VM startup and can be accessed via $moduleLoaderloadPath. It is built from the following paths.

  • A directory containing all of the standard Latitude modules, suchas 'format and 'random.
  • The current working directory (also accessible through Kernelcwd), if running in the REPL.
  • The directory containing the script file, if a script file wasinvoked from the command line (i.e., latitude some-file.lats)
  • Any directories listed in the environment variable LATITUDE_PATH(if it exists), separated by semicolons.
ModuleLoader

If you install a new package in a non-standard location, therecommended way to inform Latitude of it is by appending the path tothe LATITUDE_PATH environment variable. However, if you do not havepermissions to change environemtn variables or for some reason do notwant to, then you can clone the module loader within Latitude.

It is good practice not to mutate the current module loader but toinstead clone it and change the clone. In doing so, your changes willonly affect the current file and anything imported from the commandfile. As soon as the current file finishes executing, the originalmodule loader will return, so as not to disrupt any other code thatexpects the module loader to behave in the default way.

Summary

You now have an understanding of the basics of creating and loadingmodules. There are more customizations you can perform on the moduleloader, but most of them are scarcely needed, as the default moduleloader suffices for many common programming tasks. In the nextchapter, we’ll discuss mixin objects, a way to implement reusableinterfaces of Latitude objects.

[up]
[prev - Input and Output]
[next - Mixin Objects]

1 When using Kernelload, the lexical closure of the loaded file will be the globalscope, so any lexically-scoped variables defined in the calling file’sscope will not be visible to the loaded file. If you wish toexplicitly choose the lexical closure of the loaded file, you may useKernel evalFile, which behaves identically to Kernel load exceptthat it takes a second argument: the lexical closure.

2 The dynamicvariable $whereAmI can actually be used in several other contexts aswell. When loading a module, the variable is equal to the moduleobject. When running a Latitude script from the command line, thevariable is equal to the filename, as a string. When running theLatitude REPL, the variable is equal to the REPL object.

Moduleload

This site is open source. Improve this page.
Coments are closed

Recent News

  • IFamily For Mac
  • Winclone 7
  • Ecamm Movie Tools

Scroll to top