Aug 13, 2022Kuina-chan

This is the language specification 16 of Kuin Programming Language, and is about the advanced features of Kuin.

This page is for advanced users.

Normally, Kuin is designed so that you don't need to use the contents of this page to make it useful, but if you really want to do something special, you can make use of it.

Also, if you make even the slightest mistake, it will not work correctly and it will be difficult to identify the error, so make sure you fully understand the functions on this page and proceed with caution.

1Loading External DLL From exe

1.1Calling External DLL From exe

If you specify exe as the execution environment, you can call DLLs for x64 created in other languages. For example, write as shown in Figure 1-1 in C++ and compile for x64 in Visual C++ to create a DLL.
  1. #include <Windows.h>
  4. {
  5.   return TRUE;
  6. }
  8. extern "C" _declspec(dllexport) double Square(double x)
  9. {
  10.   return x * x;
  11. }
Figure 1-1: test_dll.cpp
If the resulting DLL is named test_dll.dll, the Kuin program can call the function in the DLL by writing Figure 1-2.
  1. func[test_dll.dll, Square]square(x: float): float
  2. end func
  4. func main()
  5.   do cui@print(@square(5.0).toStr() ~ "\n")
  6. end func
Figure 1-2:
By defining the function "func[DLL File Name,Function Name In DLL]Any Function Name(Argument):Return Value" as shown in line 1, you can call the function in the DLL as a function of Kuin as shown in line 5.
If you write a process in the content of a DLL function definition such as the first line, the DLL will be called after the process is done, but if it is not necessary, leave it empty. DLL file names can be handled with an extension other than .dll.
Now, finally, you need to copy test_dll.dll to the directory under the exe generated by Kuin. In the menu, select "Edit", then "Other Settings...". and add test_dll.dll to the related files. This will automatically copy test_dll.dll to the data folder next to the exe and call it from the exe.
When run in the CUI environment, "25" will be displayed on the screen.

1.2Value Type

The Kuin value type (non-reference type) has a correspondence with the argument and return types of DLL functions as shown in Table 1-1, and can be passed as is.
Table 1-1: Value Type Relationship
Kuin Value Type DLL Value Type
int 8byte Signed Integer Type
float 8byte Floating-point Type
char 2byte Character Type (UCS-2)
bool 1byte Boolean Type
bit8 1byte Unsigned Integer Type
bit16 2byte Unsigned Integer Type
bit32 4byte Unsigned Integer Type
bit64 8byte Unsigned Integer Type
enum 8byte Signed Integer Type

1.3Reference Type

Be careful when rewriting the reference type of Kuin on the DLL side, as it uses garbage collection for memory management. Because of the complexity of the rules, it is usually best to treat them as read-only and not rewrite them in the DLL side.
(This page is being written...)