Forum Replies Created
-
AuthorPosts
-
April 15, 2019 at 6:29 am in reply to: How to use GIT for your own projects/modules within the monkey2 repo #16174
You can add external module directories by setting the environment variable MX2_MODULE_DIRS.
In Unix shells:
Shell1export MX2_MODULE_DIRS="/users/name/monkey2/mymodules/"You can add more than one directory. Separate the directories with a semicolon “;”:
Shell1export MX2_MODULE_DIRS="/users/name/monkey2/mymodules/;/users/name/monkey2/myothermodules/"I think on Windows OS it was the command SET:
Shell1SET MX2_MODULE_DIRS=d:\monkey2\mymodulesAlternatively you can add the line to your env_linux.txt / env_macos.txt / env_windows.txt in bin/
Shell1MX2_MODULE_DIRS=/users/name/monkey2/mymodules/There is also https://rocket.chat for team/community communication.
It is open source: https://github.com/RocketChat and available for Windows/Linux/Mac/Android/iOS/Web
Just my personal opinion: I don’t think a Monkey-X book is of any help with Monkey2.
The modules are completely different, in my opinion.
The folder should be “/modules/baseinterface” and the filename “baseinterface.monkey2” if you want to #Import “<baseinterface>”.
February 21, 2019 at 6:52 am in reply to: Fist class function in collection with struct parameter #16078Wrong C++ code is generated, so you should report it at github as a bug.
As a workaround you could use Alias EventCb:Void( event:Event Ptr )
Small example:
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758#Import "<std>"#Import "<mojo>"Function Main()New mojo.app.AppInstanceLocal console := New ConsoleLocal printer := New PrinterLocal message := New MessageHelloWorld( console )HelloWorld( printer )HelloWorld( message )End#RemInterface IOutput#EndInterface IOutputMethod PrintLn( text:String )End#RemFunction HelloWorldParameter 1: Takes any object (instance of a class)that implements IOutput#EndFunction HelloWorld( obj:IOutput )obj.PrintLn( "Hello World!" )End#Remclass Console#EndClass Console Implements IOutputMethod PrintLn( s:String )Print sEndEnd#Remclass Printer#EndClass Printer Implements IOutputMethod PrintLn( s:String )Print "Printing to printer... ~n~t"+sEndEnd#Remclass Message#EndClass Message Implements IOutputMethod PrintLn( s:String )std.requesters.Notify( "Message", s )EndEnd– https://en.wikipedia.org/wiki/Interface_(object-oriented_programming)
An Interface contains declarations of methods, the parameters, and the return type.
Any class that implements the Interface is required to implement **everything**
from the Interface, exactly like it was declared.
It is like a contract/agreement and you can trust that the specific methods
are implemented in the classes.> is it possible to load the library in Monkey 2 without creating .h and C files?
Monkey2 is a little bit different because it translates to C++.
When you import something, you need to tell Monkey2 and the C++ compiler about that stuff.
If you don’t tell Monkey2, it does not know the functions.
If you don’t tell C++, it does not know the functions and you will get an error.So you need at least the Monkey2 ‘Extern’ import section and the C/C++ header with the functions/classes.
by the way I did not know how to stop the application
I put a counter 0 to 1001 in the code, otherwise it would Repeat..Forever.
The window title counts to 1001 and quits.That GetProcAddress() method brings up some casting issues,
so it is probably easier to import a “Gear3D.lib” (DLL import).
I made a quick test using LoadLibrary and GetProcAddress in a C++ file. File is attached.
Compile it and put Gear3D.dll and Link.dll in Gear3D.products/Windows/ folder, so Gear3D.exe can find the DLLs.
Attachments:
- Is Gear3D compiled for 32bit or 64bit?
- Ascii or Unicode?
- What type are the function parameters?
- InitG3D( Byte, Byte )
- InitG3D( Word, Word )
- InitG3D( Int, Int ) ?
Shouldn’t be a problem.
Please give download links for test lib and latest gear3d.
February 2, 2019 at 5:28 am in reply to: Anyone know how to convert this C/C++ initialiser?! { {0,0}, 0.5 } #16035This init part is for the struct with an array of 2 unsigned and 1 double.
C++12345678struct MixingPlan{unsigned colors[2];double ratio;};MixingPlan result = { {0,0}, 0.5 };Your struct colors[64] does not use such initialization:
C++1234567struct MixingPlan{unsigned colors[64];};MixingPlan result = { {0} };As you can see, ‘ = { values }; ‘ is used for init, and the inner ‘{ values }’ is for array init.
See also: cppreference.com >> C reference >> initialization >> array initialization
Initialization from brace-enclosed lists
C++1int z[3] = {0}; // z has type int[3] and holds all zeroesNested arrays
C++1234567891011int y[4][3] = { // array of 4 arrays of 3 ints each (4x3 matrix){ 1 }, // row 0 initialized to {1, 0, 0}{ 0, 1 }, // row 1 initialized to {0, 1, 0}{ [2]=1 }, // row 2 initialized to {0, 0, 1}}; // row 3 initialized to {0, 0, 0}struct { int a[3], b; } w[] = { { 1 }, 2 }; // array of structs// { 1 } is taken to be a fully-braced initializer for element #0 of the array// that element is initialized to { {1, 0, 0}, 0}// 2 is taken to be the first initialized for element #1 of the array// that element is initialized { {2, 0, 0}, 0}February 1, 2019 at 2:42 pm in reply to: Anyone know how to convert this C/C++ initialiser?! { {0,0}, 0.5 } #16032When I search the site for “MixingPlan” I get more than one result, and it looks like you mix them up.
1st, 2nd, 3rd search result are in the same source code:
C++12345678910struct MixingPlan{unsigned colors[2];double ratio; /* 0 = always index1, 1 = always index2, 0.5 = 50% of both */};MixingPlan DeviseBestMixingPlan(unsigned color){const unsigned r = color>>16, g = (color>>8)&0xFF, b = color&0xFF;MixingPlan result = { {0,0}, 0.5 };More search results containing “MixingPlan” show up.
Later there is a source code with a new MixingPlan struct:
C++12345678struct MixingPlan{const unsigned n_colors = 16;unsigned colors[n_colors];};MixingPlan DeviseBestMixingPlan(unsigned color){MixingPlan result = { {0} };Next one:
C++1typedef std::vector<unsigned> MixingPlan;And then, at round about the middle of the page (last search result):
C++1234567struct MixingPlan{unsigned colors[64];};MixingPlan DeviseBestMixingPlan(unsigned color){MixingPlan result = { {0} };First you need to import “<win32>”, that imports the file /modules/win32/win32.monkey2
LoadLibrary and GetProcAddress are not imported yet, so you need to add it. LoadLibraryA uses ASCII chars, so better use LoadLibraryW for wide chars (Unicode).
Monkey12345678910111213141516171819202122232425#Import "<win32>"ExternAlias FARPROC:Void PtrLoadLibraryW:win32.HMODULE( lpLibFileName:WString )GetProcAddress:FARPROC( hModule:win32.HMODULE, lpProcName:WString )PublicUsing win32..Global MyLibrary:HMODULEFunction Main()MyLibrary = LoadLibraryW("Gear3D.dll")Local SetGraphics3D(alto:Int, ancho:Int) = GetProcAddress(MyLibrary,"_SetGraphics3D@4")SetGraphics3D(1024,768)EndIf LoadLibrary() and GetProcAddress() get added to the win32 import, you could remove the ‘Extern’ section.
Of course untested, but that’s the general way how it would work with dynamic loading of DLL functions at runtime.
If you have a DLL import file (.lib), you could directly import it. If the DLL uses ASCII strings, a conversion from Unicode to ASCII would be required for the strings.If you have a Unicode version of the .dll you would use this.
-
AuthorPosts