How to call lua in CSharp – C#

Thursday, April 27th, 2017 (0 Comment)

Sometime, we need to change some business rules by use script lua in CSharp without combine or re-build our project.

We should know about LUA Script programming (we can develop lua in lua.org/cgi-bin/demo to check syntax), it help us develop many dynamic business rules without build/combine project again.

Example: We have one rule as below: C = A + B, after that user change rule to C = A*B. This time, we only edit Lua script file and upload to system, we do not need to open project to edit code and re-combine, re-deploy …

In this article, we practice a sample C# code that how to call lua in C#

1) Create some functions in lua script to call lua in CSharp

example.lua file

2) Call lua in CSharp

In dotnet, we need use NLUA library. We use Mange Nudget Packages to install NLUA for dot net (right click on project in Visual Studio and select Mange Nudget Packages and type NULA and install)

Code call lua in CSharp

Output:

 

Tags: , , , , ,

Related Posts

csharp
How to send mail csharp – C#
csharp
Connection to ldap in csharp – C# simple
csharp
Convert object to json in CSharp – C# and vice versa
csharp
Encode and decode in CSharp – C#

Related Posts

csharp
How to send mail csharp – C#
csharp
Connection to ldap in csharp – C# simple
csharp
Convert object to json in CSharp – C# and vice versa
csharp
Encode and decode in CSharp – C#

Leave a Reply

Your email address will not be published. Required fields are marked *