Hi, On Wed, May 8, 2024 at 2:11 PM Lifepillar <[email protected]> wrote: > > On 2024-05-07, Girish <[email protected]> wrote: > > On Sunday 5 May 2024 at 15:39:53 UTC+2 Lifepillar wrote: > > >> Let's say I have this class in some `foo.vim` file: > >> > >> export class Config > >> public static var option = false > >> endclass > >> > >> Now, I'd like to set `Config.option` to `true` from a script and from > >> the command line. From a script, I can do this: > >> > >> import "foo.vim" > >> > >> type FooConfig = foo.Config > >> FooConfig.option = true > >> echo FooConfig.option # OK > >> echo foo.Config.option # Also works > >> > >> Unfortunately, this gives an error (Undefined variable Config): > >> > >> foo.Config.option = true > >> > > Looks like a bug. Should be able to do `foo.Config.option = true` > > Indeed. And fixed. That works with the latest Vim (9.1.399). >
Yes. This should be addressed by patch 9.1.0398. If you see any additional problems in using different types of imported variables in a Vim9 script (after this patch), please open an issue. In particular, look for any issues in using nested types. > > >> But how do I access the class member from the command line? Is that even > >> possible? > > I still haven't found a way to do that, and I'm starting to think that > it is not currently possible. If I put this in ~/.vim/autoload/foo.vim: > A class in a Vim9 script is a script-local variable. So it cannot be directly accessed from outside the script (without using the script name). Regards, Yegappan > vim9script > > export var x = 42 > > export def F() > enddef > > export class C > public var setting = "ok" > public static var option = false > endclass > > export var config = C.new() > > Then these work from the command line: > > echo foo#x > call foo#F() > echo foo#config > echo foo#config.setting > > But I can't find a way to access the static variable 'option'. > > Life. -- -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAAW7x7ksKt7Dq3mceEz2JjYab3vWeGbBgOWNoP9BeLXqqsPtRw%40mail.gmail.com.
