Re: [code] [textadept] Required Modules

From: Mitchell <m.att.foicica.com>
Date: Wed, 14 Aug 2019 16:24:24 -0400 (EDT)

Hi Qwerky,

On Wed, 14 Aug 2019, Qwerky wrote:

> Hi.  If the user init.lua requires a module [foo = require('foo')] which has
> a function 'bar', is that module and its function then available to all other
> modules?
>
> So, in keys.lua, can one write 'keys.ab = foo.bar'?  Or, does 'foo' need to
> be required in keys.lua, as well as every other module which uses 'foo.bar'?

It depends.

From your *~/.textadept/init.lua*, the statement:

   foo = require('foo')

defines a global variable `foo` that, from this point forward in Textadept's init process, is available to all code that comes after (including required modules). However, any modules loaded prior to that statement (such as *~/.textadept/modules/textadept/keys.lua*) can access global `foo` from within functions (not at top-level file scope).

In your case for *keys.lua*, you'd probably need `keys.ab = require('foo').bar` since it's at top-level file scope and Textadept loads that before your *~/.textadept/init.lua*.

I hope this makes sense.

Cheers,
Mitchell

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Wed 14 Aug 2019 - 16:24:24 EDT

This archive was generated by hypermail 2.2.0 : Thu 15 Aug 2019 - 06:49:10 EDT