Wednesday, May 31, 2023

Re: passing vim9 vars to python3

Hi Bram,

Thank you I knew, this is working 

vim9script

def g:Py3_SimpleMinimalTest(yml_fpath: string): void
  w:yml_f = yml_fpath
  exe 'py3 print(sys.version)'
  exe 'py3 print(vim.current.window.vars[''yml_f''])'
enddef

and what about making this works

def g:Py3_SimpleMinimalTest(yml_fpath: string): void
  var yml_f:string  = yml_fpath
  exe 'py3 print(sys.version)'
  exe 'py3 print(vim.current.????.vars[''yml_f''])'
enddef

Thank you
Le mercredi 31 mai 2023 à 13:48:23 UTC+2, Bram Moolenaar a écrit :

> Seeing the legacy vimscript func* Test_python3_vars()* in
> *src\testdir\test_python3.vim*,
>
> Can you confirm that in vim9script, those setlines test are no possible to
> be written in same way to be passed to python3 world ?
>
> func Test_python3_vars()
> let g:foo = 'bac' -- << -- THE ONLY ONE CAN BE USED in vim9 ?
> let w:abc3 = 'def' -- << -- NOT POSSIBLE in vim9
> let b:baz = 'bar' -- << -- NOT POSSIBLE in vim9
> let t:bar = 'jkl' -- << -- NOT POSSIBLE in vim9

I guess you mean that in Vim9 script and in a :def function the "let"
command doesn't work. You can just leave it out, e.g.:

w:abc3 = 'def'

> Beyond a simple variable, is it possible to move a VIM9 class to the
> python3 world?

You mean to pass a reference of the class and use it in Python? No,
that is not possible. The class implementation is only halfway, but
even when the work has been done a Python script will not be able to
access a Vim class directly. You can only use it in a Vim script
context, such as using "vim.eval()".

--
Do not trust atoms, they make up everything.

/// Bram Moolenaar -- Br...@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/d1af74ca-a97b-4e41-8069-e37d10ff68ddn%40googlegroups.com.

No comments:

Post a Comment