XeNTaX Forum Index
Forum MultiEx Commander Tools Tools Home
It is currently Fri Mar 24, 2017 1:20 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: c# - DynamicLua - Few Q's
PostPosted: Sat Apr 23, 2016 8:28 pm 
Offline
n00b
User avatar

Joined: Sat Sep 12, 2015 2:16 am
Posts: 18
Location: South Africa
Has thanked: 10 times
Have thanks: 2 times

Hi !

Hoping to ask advice of anyone that has more experience working with DynamicLua or similar library in c# - i think more c# related though...

Persistence / referencing to or from other class/namespace:-

From what i Understand about dynamic types (which is zero) they do not persist, and only accessible locally, within the class, so ive been creating some methods, to perform whatevr queries.

If i wanted to access the same Lua instance from other namespace/class without passing that class as a reference how would it work. If i created new dynamic Lua instance in the same application, would it connect to the initial tables created from other instance, or is it completely seperate ? what is best way ofdoing this, without explicitly creating a new instance of the class that contains that main instance - when i make that class static, or the dynamic lua instance itself - it doesnt seem to work (seems to be only way i know that could make it accessible throughout app)

Seperately:- is there any preferred method,to get some manner of printout of the entire Lua DB, tables/funcs etc. something like a json structure,or just list of tables/func names etc, (Iterate through, use GetDynamicMemberNames ?)

Finally:- why have i seen some cases of guys creating main tables through a new Object[] rather than just stringName of table, or in Queries, referencing the main Table/Root Through testing isee that it can be used to create hierarchy, but is there any other reason im not aware of

Google failed, & not much activity on DynLua page, so any help appreciated

Cheers

You can make the ads go away by registering



Top
 Profile  
 
 Post subject: Re: c# - DynamicLua - Few Q's
PostPosted: Sat Apr 23, 2016 9:33 pm 
Offline
beginner
User avatar

Joined: Sat Sep 27, 2014 9:19 am
Posts: 33
Location: 127.0.0.1
Has thanked: 0 time
Have thanks: 12 times
In terms of an active Lua implementation for C#, I would recommend checking out MoonSharp:
http://www.moonsharp.org/

The developer is active and the most recent update was pushed 2016-02-09

In my opinion, it is one of the better implementations in terms of speed and optimization for Lua < > C#. However in a large scale project that heavily uses Lua you will notice some massive overhead and slow down. (If you need a true implementation of Lua in your project, go with a true Lua implementation in C/C++.)

Dynamic in C# is not restricted to classes only, you can use it anywhere. You can read up more on the dynamic keyword here:
https://msdn.microsoft.com/en-us/library/dd264736.aspx

In terms of accessing a Lua instance globally you can use a singleton approach to make a 'Lua Manager' type class to access the Lua state globally. That would be one of the more easier methods of being able to do stuff with a single Lua instance from anywhere in your project.

When you create multiple Lua instances they are entirely separate from each other. Lua does not communicate with multiple states by itself. If you want something like that you will have to code it manually. (Mind you it will involve a hefty amount of work for large scale projects that heavily use Lua.) Lua instances are not designed to communicate between each other. Think of a Lua state like a virtual machine without networking. Everything is closed off to the VM itself. But you can make multiple instances of a VM etc.

As for printing out the entire Lua DB/tables/funcs/etc. you can dump the global object _G. Iterate over its members and dump each part of it, if its a table, step into that table and dump that as well etc. An example of that can be found here:
https://codea.io/talk/discussion/138/co ... -variables
(There are other examples of similar around the net.)

----

Just keep in mind with a C# based Lua implementation there is a lot of overhead. When you want to use a C# object from Lua there is a lot of translation layers going on. The object has to be converted to a Lua friendly instance which usually involves a large amount of reflection being used which turns into more overhead. Accessing the object from Lua also has multiple translation layers going back and forth too. For example if you have a class with some variables and functions that you expose to Lua, there is going to be multiple layers of reflection and translation between C# and Lua using the same object.

If Lua wants to use a variable from the object, such as:
someObject.x = 123;

There is going to be a layer translating someObject to the C# instance, then reflection will be used to find the 'x' property and its type. The 123 will be converted to the appropriate type via more reflection of the properties information and so on.

This can lead to serious overhead and lag if you are constantly talking between the C# app and Lua.


Top
 Profile  
 
 Post subject: Re: c# - DynamicLua - Few Q's
PostPosted: Mon Apr 25, 2016 10:40 pm 
Offline
n00b
User avatar

Joined: Sat Sep 12, 2015 2:16 am
Posts: 18
Location: South Africa
Has thanked: 10 times
Have thanks: 2 times
atom0s wrote:
In terms of an active Lua implementation for C#, I would recommend checking out MoonSharp:
http://www.moonsharp.org/

The developer is active and the most recent update was pushed 2016-02-09
a
In my opinion, it is one of the better implementations in terms of speed and optimization for Lua < > C#. However in a large scale project that heavily uses Lua you will notice some massive overhead and slow down. (If you need a true implementation of Lua in your project, go with a true Lua implementation in C/C++.)

Dynamic in C# is not restricted to classes only, you can use it anywhere. You can read up more on the dynamic keyword here:
https://msdn.microsoft.com/en-us/library/dd264736.aspx

This can lead to serious overhead and lag if you are constantly talking between the C# app and Lua.


Mate, thank you for such a detailed reply, wasnt expecting as much, so cheers :)

I am definately going to give it a go - currently ive found some workarounds here there, but its all such a headache, and there is virtually no way of properly tracking, and handling exceptions with DynLua, just a craptonne of Unknown fatal this error that error spewing out, half the time, and cant even begin to tell where its coming from :/ have to literally test each tables existence and double check vars on setting to even be sure it worked, mucho headache



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group