VB6 - Lua Integration - scripting

I'm wondering if anyone has any tips for integrating Lua and VB6. I am running a small Online RPG that would be awesome to add some scripting to.

Well, it is doable. I once did it for Lua 5.0.2 but I can't find the files. Among the options you have, you can:
Wrap Lua in a COM dll exposing the Lua API, so in VB you can add a reference to it.
Build your custom Lua version, using the __stdcall calling convention, so you can use Declare in VB to import the needed Lua functions. Writing a Type Library will ease a lot the integration with VB (mainly, it will do the conversion from C strings to VB strings for you).
Build a wrapper DLL, that replicates Lua's interface but using __stdcall, adding the functions that are defined with macros, etc.
I remember that using a custom built Lua, I could register VB functions (defined in modules) into Lua and call them from a script. I don't recall if I ever got it to call member functions.
I hope this can get you started.

Use LuaInterface. It's a .NET Library that allows you to use lua. However it doesnt come with docs in and of itself, look at this for some helpful guides.
Basically, you add the DLL to your project and reference it/add using satements, then create a new Lua object. From there, you can access it like an array to extract variables, and there are methods to call lua functions and manipulate tables.

Related

Calling Matlab from VB

I am building an application in VB (VS2012) and the main code is written in Matlab. I would like to call the Matlab scripts from the VB form and also display the results of the calculations in the VB form in a datagrid. Can somebody suggest what my mode of exchange should be?
Thanks for the help.
You have two main options.
MATLAB has a COM interface. From VB, you can start an instance of MATLAB, pass data to it, execute commands, retrieve results, and quit MATLAB. To find out more, take a look at the documentation pages for the MATLAB COM Automation Server. This method will require you to have a live copy of MATLAB present when you run your VB application.
You can use an add-on product to MATLAB, MATLAB Builder NE for .NET (you'll also require another add-on that it depends on, MATLAB Compiler). MATLAB Builder NE allows you to convert your MATLAB code into a standalone .NET assembly or COM component that can be called from your VB application, and distributed with it.
Note that contrary to a comment, MATLAB Compiler alone without MATLAB Builder NE does not allow you to produce .NET assemblies.

vb.net: is it possible to import FreeImage.dll to vb.net?

I need to read\write tga files from vb,
I found TargaImage.dll, nice lib but it allows only read tga.
I found FreeImage, tryed to import it in vb, but it says:
FreeImage.dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
I think I have to use , but absolutly dont know anything.
help plz:)
From looking at the way the distribution works, you have two options:
First, you could call the functions in the DLL directly using <DllImport> attributes. This is going to require a lot of learning of how to make calls to unmanaged DLLs, passing the right values, etc. Which is why I suggest the second option.
The second option is, you can use the .NET Wrapper project that is included in the distribution. If you're using a version of Visual Studio that supports multiple programming languages, just add the wrapper project to your solution and reference the wrapper project from the project that needs to use it.
If you're using Visual Studio Express, you won't be able to add a C# project to a VB solution. I'd suggest downloading C# Express, compiling the wrapper project, and then adding the compiled DLL to your VB.Net project.

Call .net methods into java without using C/C

Can anybody explain how can i call .net methods(from .dll) in my java code but i dont want to write/use C/C++ Code please expalin it Step by Step
You haven't given us any information to work off (How large are the two projects? Are you forced to use a specific CLR/JRE? Can they be two separate processes or do you just need to access a bunch of methods? Stuff like that), but I can point you in a general direction...
IKVM.NET is an implementation of Java that runs on the CLR. If you run your Java program in there, you can interop with any other .NET language easily.
If you can't use this for some reason, then you're probably going to have to embed Mono in your application and write some JNI bindings to start an instance of the CLR, then load and invoke your code.
If you've got a small amount of methods, consider just porting the code to Java instead of creating this huge system in order to get a small amount of functionality.
I can't explain it step by step because you haven't provided very much information as to what restrictions you have or how it needs to be done. Also, this isn't something trivial. You're trying to get two language runtimes to interact with each other without using native code, when native code is the only thing either runtime can interoperate with.

Objective-C runtime code generation

I want to create an Objective-C application which lets you specify a class implementation at runtime.
I want the user to type some code (correctness of the code is out of scope for now).
When the user is done i want to create a class of the typed code and use it in the application.
So i want to dynamically add code in runtime of the application. Is this possible?
If so, how can i achieve this? If not, why not and are there any alternatives to create the same effect which i want to create?
Thanks.
You can dynamically load classes at runtime, but to get there you'd first need to handle distributing a compiler, its compilation dependencies (headers, ...), setup its enviroment, etc.
Usually applications use scripting languages that are painlessly embeddable (Lua, Python, ...) or already available on the platform (JavaScript, AppleScript, ...).
I'd check out F-Script. It's closer to smalltalk than Obj-C, but IMO it's closer to Obj-C than JavaScript or Lua :-)
On iOS devices, this isn't possible. On a Mac you could link against the clang+llvm libraries and use them to generate code into a buffer, then mprotect() the buffer to be executable, I believe.

Is there anyway to export a function (not a class) in VB6?

I want to create an ActiveX DLL from Visual Basic 6 from which I would like to call some public functions. I will call this DLL only from VB6. However, it seems that only classes get exported. Is there any workaround?
I know there is a way to create DLLs from VB6 with standard WINAPI functions. This is not what I want, because I would have to type thousands of Declare instructions, and I would lose the dynamic linking so I don't need to recompile applications when changing the DLL.
I will state my problem just in case anyone has a better idea. I've got a bunch of relatively big projects, each with its own code, and then I have a lot of "Generic" code which is used in several projects. It's an annoyance to add every file to each new project, and having to recompile all of them for each minor change. So I thought of creating a DLL, so I would just "Add reference" when I begin a new project, and don't have to worry anymore about recompiling (at least for minor changes) but I raged when discovered that only classes got exported.
I wouldn't mind to reorganize the code in classes, but it's an overwhelming task: there are some 10 years of 3-4 people code, so it's not something I can do overnight.
Yes, it's easy.
Put all the utility routines in special classes in the DLL.
Set the Instancing property of those classes as GlobalMultiUse.
Build the DLL.
In your client project (with a reference to the DLL) you will now be able to call the functions and subroutines as if they were in a module in that project. You won't need to create any objects.
You can read more in the VB6 manual.