Could do with some guidance on Lua interfacing please

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Could do with some guidance on Lua interfacing please

Geoff Smith


Hi


I am tinkering around with adding some basic Windows Forms functionality from Lua into My C# App. I am using LuaInterface as the glue.


I decided to firstly ignore the Lua syntax and just try and get something working and then re look at the Lua syntax later. I am at that point now but not too sure how to proceed.


I have got code like this to create a Windows Form


local frm1 = myApp.newForm ({})    -- The passed in table contains form init params, omitted for brevity


in the c# code the function newForm() just simply return the c# Windows Form instance, which then gets returned to Lua as a Userdata (LuaInterface handles that conversion)


I can then call a method of the form in Lua by this code


  myApp.method(frm1 , "Show")


this all works fine and in the C# code it calls frm1Show() to display the form.


The obvious thing I dont like about that is the horrible syntax, I want to be able to call something like frm1.show() in Lua.

How would I go about rejigging that syntax construct ?  Any tips would be greatly appreciated, thanks


Geoff





Reply | Threaded
Open this post in threaded view
|

Re: Could do with some guidance on Lua interfacing please

Duncan Cross
On Sun, Jan 31, 2016 at 1:05 PM, Geoff Smith <[hidden email]> wrote:
> The obvious thing I dont like about that is the horrible syntax, I want to
> be able to call something like frm1.show() in Lua.
>
> How would I go about rejigging that syntax construct ?

In Lua syntax, the way to call an instance method is
objectname:methodname(...) with a colon instead of a dot. (This is
general advice, rather than specific to LuaInterface.)

-Duncan

Reply | Threaded
Open this post in threaded view
|

Re: Could do with some guidance on Lua interfacing please

Geoff Smith
Hi Duncan

Thanks for the reply, yes sorry that was more of a typo on my part

I really meant Ideally   frm1:Show()      -- Syntax sugar for  frm1.Show(frm1)

For the actual problem, I am hazy but I think I probably need to construct a lua table in C# and return that Lua table. It would contain maybe 2 elements
a) the C# ref to the form instance, and b) a lua function Show(). which then calls back into C# to do the actual showing of the windows form.

Or alternatively is there a way to implement this using metatables and metamehods ? hmmmm not sure.

I wish the documentation for LuaInterface was better, and with more examples of how to use it !

Geoff
________________________________________
From: [hidden email] <[hidden email]> on behalf of Duncan Cross <[hidden email]>
Sent: 31 January 2016 14:25
To: Lua mailing list
Subject: Re: Could do with some guidance on Lua interfacing please

On Sun, Jan 31, 2016 at 1:05 PM, Geoff Smith <[hidden email]> wrote:
> The obvious thing I dont like about that is the horrible syntax, I want to
> be able to call something like frm1.show() in Lua.
>
> How would I go about rejigging that syntax construct ?

In Lua syntax, the way to call an instance method is
objectname:methodname(...) with a colon instead of a dot. (This is
general advice, rather than specific to LuaInterface.)

-Duncan