Lua .NET How to use the standard and third party libraries - c#

I am using Lua inside C# WinForms application for GUI automation testing. I want to use the logging library http://www.keplerproject.org/lualogging/
But I don't know where to copy those logging library files and other standard lua files so that I can use the standard lua logging within the lua scripts.
I see something like LUA_PATH but still I don't understand how to make the lua packing strcuture without installing it.

Did you tried to use LuaRocks.
Most libraries (including lualogging) are in the repositories, and the install is straightforward : luarocks install lualogging.
About the environment variables, you have to define two : LUA_PATH and LUA_CPATH.
If i'm correct, LUA_PATH is for the Lua libraries (i.e. mylib.lua), and LUA_CPATH is for the compiled binding to a native library (e.g. lsqlite3.so for the Sqlite binding).
Hope this helps.

Related

How to compile c#/c++ files from Java Application

I am just looking into compilers and I was wondering is it possible to compile both c# and c++ files from a Java Application (e.g. to compile java from a java application you can use the JavaCompiler API). I have looked online for this but all i can find is ways to compile java files from c# and c++ and not the other way around.
If so, what API's can you use for this?
If you know the system commands for compiling and executing .cpp files(don't know much about c#) you might want to check out this. It details how to execute system commands from a Java program. Pass the system commands for compiling the required file in Runtime.getRuntime().exec().
Consider learning how to call ant from Java code and using something like this ant enhancement.
Disclaimer: I don't know anything about this product, but found it by searching for "can ant build c++?"
For C# in Windows: compiler (csc.exe) is part of .Net install on Windows and can be found at well known location (like %windir%\Microsoft.NET\Framework\v3.5 for .Net 3.5). The same place also contains MSBuild.exe that can build project files (*.csproj).
Your code may need to provide locations for referenced libraries if using Csc.exe to compile individual files.

How to export c# function so it can be called from unmanaged environment?

I would like to know how can I export a function so I can use it in other programming language?
I want to use the dll functions in unmanaged programming language.
What can I do?
You will need to run regasm.exe with the /tlb command against your .NET assembly and then reference the output type library (tlb) from C++.
I've done this many times before and it can be a pain, especially when you go to deploy it. I recommend using the /codebase switch, which tells the registry where to find your .NET assembly when its classes are instantiated in a COM context. That makes it easy to find in the registry and tweek it as necessary.
Two articles that may be of use... it sounds rather painful:
An Overview of Managed/Unmanaged Code Interoperability
Exposing .NET Framework Components to COM

How to get GUID (Assembly attribute) of a C# assembly in c++

I am trying to read GUID attribute of a C#.net assembly from c++ (VC++ 10).
I should mention that, I don't want to use .net or .net reflection. looking for a pure c++ way.
what is the solution ?
Thanks in advance.
You need to use the Unamanaged Metadata API
and especially the IMetaDataImport::EnumCustomAttributes Method
That's going to be quite a work... Here is a link that gives a good starting point on this (it's C#, but the ideas are exactly the same, and is in fact easier to program in C++): Reading types from assembly
Check out the The .NET File Format MetaSection over at CodeProject.
i understand you don't want to use reflection or .net.
You do however want to get the GUID from a C# dll you have, that was built with .NET.
The common way C# developers make their class libraries available to COM-based developers is to use the tlbexp.exe (type library export) tool to export a type library file.
The COM-developer can then use the .tlb file in their COM code.
When the C# developer builds the dll they either put the Guid manually in the AssemblyInfo level (in .NET) or the compiler will generate the Guid automatically when building the dll.
show how the COM client (C++) is built to use the COM server (C#)
http://msdn.microsoft.com/en-us/library/aa645738%28v=vs.71%29.aspx
note that in this article refers to another tool regasm.exe which registers the dll and can export the tlb at the same time but it is not necessary to register the dll on your system
as a developer you can just use the tlb file

Exporting functions from a C# class library

How would I export functions defined in a C# class library, while enabling them to be imported to and called from an unmanaged C++ application/DLL ?
Strictly speaking, you can't just export functions as you would in a classic .dll, as .NET .dll's aren't really .dll's at all. Your only three options are:
Use managed C++
Expose your C# classes as COM objects and consume them from your C++ code
Host the .NET runtime in your C++ project and interact with your C# classes through that.
Your C++ Apllication would have to start by hosting the CLR. There is nothing special required from the .NET DLL.
You would not. Not supported. You can pretty much only export COM objects from a C# class librarly.
You could also make a C++ wrapper for your C# library - a simple Managed C++ DLL that would import .NET methods and export them natively. This adds an additional layer, but it might be useful if C# library is a must have.
Another option is to tweak the compiled assembly to export the functions. A C# compiler cannot do this, but it takes a slight change of MSIL code to get the things done.
Have a look at this article - there're some links on how the stuff works, and a tool to automate it (though I haven't tried it myself).

Packaging script source files in IronPython and IronRuby

Does anyone know how to add python and ruby libs as a resource in a dll for deployment? I want to host a script engine in my app, but dont want to have to deploy the entire standard libraries of the respective languages in source files. Is there a simple way to do this so that a require or import statement will find the embedded resources?
You could add custom import hook that looks for embedded resources when an import is executed. This is slightly complex and probably not worth the trouble.
A better technique would be to fetch all of the embedded modules at startup time, execute them with the ScriptEngine and put the modules you have created into the sys.modules dictionary associated with the engine. This automatically makes them available for import by Python code executed by the engine.
You can create StreamContentProviders for example
In the ironrubymvc project under IronRubyMVC/Core/ you will find what you need.
AssemblyStreamContentProvider
Usage of the ContentProvider
IronPython 2.0 has a sample compiler called PYC on Codeplex.com/ironpython which can create DLL's (and applications if you need them too).
IronPython 2.6 has a newer version of PYC under Tools\script.
Cheers,
Davy

Categories