Wednesday, May 31, 2023

Re: passing vim9 vars to python3

> - From vim9 help I see *Functions and variables are script-local by
> default*
>
> So s: is no mandatory no?, because if I put s: I see E1268:
> Cannot use s: in Vim9 script: s:yml_f = yml_fpath.

You need to declare the variable at the script level first. You cannot
create a script variable in a function. This is so that when accessing
the variable from a compiled function it knows where it is, it does not
need to be looked up by name (which is much faster).

> - So I delete s: and obtain this
>
> 3.12.0b1 (tags/v3.12.0b1:5612078, May 22 2023, 16:20:31) [MSC
> v.1934 64 bit (AMD64)]
> <vim.dictionary object at 0x0000020790DC9380>
>
> regarding this code :
> vim9script
>
> def Py3_SimpleMinimalTest(yml_fpath: string): void
> var yml_f: string = yml_fpath
> exe 'py3 print(sys.version)'
> exe 'py3 print(vim.current.buffer.vars)'
> exe 'py3 print(vim.current.buffer.vars[''yml_f''])'
> enddef

This will certainly not work, since "vim.current.buffer.vars[]" refers
to buffer-local variables. You could change the first line in this
function:
b:yml_f = yml_fpath

But is this really buffer related? And it does require a runtime lookup
by name. Using a script-local variable will work better.


--
There's no place like $(HOME)!

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
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 vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20230531213005.3A2D11C1B32%40moolenaar.net.

No comments: