luaeval returns number out of float

10 views
Skip to first unread message

Nikola

unread,
Jun 6, 2023, 4:48:06 AM6/6/23
to vim_use
Hi, 

I use luaeval to compute some float result.
 these floating values are returned 
 to vim9 defined func which itself returns float type. 

When i run a try, vim echoes error E1012: type mismatch; expected float but got number. 


Code:
def Foo(): float
 return luaeval('require("compute.utils" ).luamethod(_A.x,_A.y)', {'x' : '2.0', 'y' : '1.0' }) 
enddef

When i print returned value of lua méthode, it prints 1.0


Huge version of gvim9 built with patch 1610 under Win10 with +lua interface. 

Thank you 
Nikola

Nikola

unread,
Jun 6, 2023, 4:54:41 AM6/6/23
to vim_use
Lua dll used version is 5.4.6.

Bram Moolenaar

unread,
Jun 6, 2023, 12:57:09 PM6/6/23
to vim...@googlegroups.com, Nikola

> I use luaeval to compute some float result.
> these floating values are returned
> to vim9 defined func which itself returns float type.
>
> When i run a try, vim echoes error E1012: type mismatch; expected float but
> got number.
>
>
> Code:
> def Foo(): float
> return luaeval('require("compute.utils" ).luamethod(_A.x,_A.y)', {'x' :
> '2.0', 'y' : '1.0' })
> enddef
>
> When i print returned value of lua méthode, it prints 1.0

I get an error for loading compute.utils:
[string "luaeval"]:1: module 'compute.utils' not found:
<09>no field package.preload['compute.utils']

Does that need to be installed first?

There are a couple of errors in the code that you should have noticed:
There should not be a space before the colons in the dictionary.

I assume you call the function with "echo Foo()"?

I cannot guess what the problem is, this appears to work fine:

def Foo(): float
return luaeval('math.pi')
enddef

--
I have a watch cat! Just break in and she'll watch.

/// 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 ///

Nikola

unread,
Jun 7, 2023, 3:53:23 AM6/7/23
to vim_use
Hi Bram
Thank you for answer. 

Considering this minimal reproducing test which succeed as your,
 it doesn't come from api vim-lua, but from my own middleware vim9 script, 
I will have to look furthermore the params'values i pass. 

Ps: Forget the code and space errors, it was just the idea. 
compute.utils was just to say i use and require a lua helper script of my own. 
Vim9 client code --  vim9 export def func -- lua helper script 

Thank you for your help, I will see that. 
Nikola
Reply all
Reply to author
Forward
0 new messages