Forum Replies Created
- 
		AuthorPosts
 - 
		
			
				
Perhaps it would be a good idea for Monkey to do an Assertion for notifying users explicitly.
Perhaps there would be a new need for a module be created called “Localization”.
I have spent a few minutes creating a module to let you get the raw system locale (you will have to interpret it with custom rules in your program).
Basically it depends on this: http://www.cplusplus.com/reference/clocale/setlocale/
But of course the module will have to properly designed and planned so it contains various useful features and a reasonable API. We can throw a bunch of high level ideas and then use them as a placeholder for implementation.
Monkey123456789#Import "<std>"#Import "<localization>"Using localizationFunction Main()Print("Testing Localization")Local language := GetLanguage()Print(language)EndAttachments:
Looks very good.
wow, it’s getting better.
It seems that there are various conventions on how to write strings.
http://wiki.freepascal.org/Character_and_string_types#StringThe STRING+NULLBYTE is the Ansi String (what monkey has)
The STR_LENGTH+STRING is the Pascal String (what the file format has)The problem was that I had not notice what sort of strings the file format used. I got inconsistent results among Monkey+C#+C++ because of not knowing the convention. :-S
I can add simply a ReadPascalString method to the binary reader and close this.
Oh so this means that CStringLength is the raw string format, right?
Something else, I updated the code today but still it fails. For the sake of example, I coded the data generator again in C, this is as close as it gets to what the problem is. Monkey and C# might have been better design to avoid this confusion, but C is something different. I might have to do unicode conversion or bitshifting (null bytes might be bishifted to the other bytes).
Monkey12345678910111213141516171819#pragma warning(disable : 4996)#include <stdio.h>int main(){int num;FILE *f;f = fopen("cdata.something", "w");fprintf(f, "%d", 10);fprintf(f, "%s", "HELLO");fprintf(f, "%d", 100);fprintf(f, "%s", "MONKEYCODER");fclose(f);return 0;}No more no less I captured the output in the screenshot.
Attachments:
I don’t know exactly how these instruments are properly designed. I could guess that you would start looking at some VST plugins – some of them are exact replicas of 80s synths and that make them sort of standard. Otherwise there is a more modular approach that would allow the user to add the components together as building blocks.
Buffer.PeekCString helps a lot because it stops when it detects the 0 byte.
monkeydoc: Reads a null terminated CString from the databuffer.However PeekString is designed differently.
monkeydoc: all bytes from offset until the end of the data buffer are readI tried as well PeekCString to see if it works but it gives the same number (which is 7 ).
Monkey123Print(s.Length)Print(s.CStringLength)DebugStop()I looked at it further today and I found differences on how CSharp + Monkey writes the data buffer. However I found a better way to read the string (which works both fine for the C# data and the Monkey data – hopefully would be universal). It seems that PeekCString does the work fine however there was some trickiness involved in figuring out the offsets and lengths on how the string is peeked and the pointer is advanced.
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041' databufferead.monkey2 '#Import "<std>"Using std.filesystemUsing std.memoryClass DataBufferReaderField Position:IntField Buffer:DataBufferMethod New(file:String)Position = 0Buffer = DataBuffer.Load(file)DebugAssert(Buffer <> Null, "Could not open file: " + file)EndMethod ReadInt:Int()Position+=4Return Buffer.PeekInt(Position-4)EndMethod ReadString2:String()Local s := Buffer.PeekCString(Position)Position += s.Length - 1 ' ignore the null terminator [\0]s = s.Slice(0, s.Length - 1) ' discard the null terminatorReturn sEndEndFunction Main()Local file := AppDir() + "..\..\csharpdata.something"' Local file := AppDir() + "..\..\monkeydata.something"Local reader := New DataBufferReader(file)Local int1 := reader.ReadInt()Local str1 := reader.ReadString2()Local int2 := reader.ReadInt()Local str2 := reader.ReadString2()DebugStop()EndMonkey12345678910111213141516171819202122232425262728293031323334353637383940' databufferwrite.monkey2 '#Import "<std>"Using monkey.debugUsing std.filesystemUsing std.memoryClass DataBufferWriterField Position:IntField Buffer:DataBufferMethod New(capacity:Int)Position = 0Buffer = New DataBuffer(capacity)EndMethod WriteInt(i:Int)Buffer.PokeInt(Position, i)Position += 4EndMethod WriteString(s:String)Buffer.PokeString(Position, s)Position += s.LengthEndMethod Save(path:String)Buffer.Resize(Buffer.Length)Buffer.Save(path)EndEndFunction Main()Local buffer := New DataBufferWriter(100)buffer.WriteInt(10)buffer.WriteString("HELLO")buffer.WriteInt(100)buffer.WriteString("MONKEYCODER")buffer.Save(AppDir() + "..\..\monkeydata.something")EndAttachments:
Otherwise if you want to test the default peek string method you would see some problems:
Monkey123456Method ReadString2:String()Local s := Buffer.PeekString(Position)Position += s.LengthDebugStop()Return sEndWhat I have been learning the past few months for architecture is that – it’s better to make clear cuts on the codebase early on and call them “subprograms” or “modules” or “libraries” and let them do their own thing have their own state.
One great example is comes from using a physics engine (BEPU/chipmunk/box2d) where there is the World and you add Bodies. And therefore you can update the World (which updates all the Bodies) or having a reference to a Body you would control it (move it around etc). This you can call it a library. Another example is with the Audio engine contraption. Where you load a bunch of sounds in a list and then you simply call the play sound method. This you can call it a module.
This approach is the “modular” approach which means is exactly what you would do in C where there are no classes etc. On the other hand if you go with an Object Oriented approach you code will be an endless composite fractal which might give you confusion. So by expanding upon this idea you can simply let each subsystem do it’s own thing without mixing them all together.
P.S. After studying the Doom 2 source code and other lots of C games – I have gradually reduced my OOP to exactly only where is essential.
This was really good.
Wow can’t wait to try it. I am a musician as well so I might be able to create a few things with it.
 - 
		AuthorPosts
 


