The stack again

So I had trouble accepting a string that was 256 bytes big. Reducing the size of the string to 128 bytes worked perfectly.

So I tried creating a function that accepts three strings that are 128 bytes long, and see what that does to the stack. It seems to be perfectly ok.

I created this script:

vmthread MAIN
{
	CALL( WriteLog, 'Hello log world' )
	CALL( WriteLog, 'What is going on?' )

	CALL( WriteLog2, 'String1', 'String2', 'String3' )
}

subcall WriteLog
{
	IN_S	Message		128

	DATA16 hLogFile
	FILE( OPEN_APPEND, 'log.txt', hLogFile )
	FILE( WRITE_TEXT, hLogFile, DEL_NONE, Message )
	FILE( WRITE_BYTES, hLogFile, 1, 10 )
	FILE( WRITE_BYTES, hLogFile, 1, 13 )
	FILE( CLOSE, hLogFile )
}


subcall WriteLog2
{
	IN_S Message1 128
	IN_S Message2 128
	IN_S Message3 128

	DATA16 hLogFile
	FILE( OPEN_APPEND, 'log.txt', hLogFile )
	FILE( WRITE_TEXT, hLogFile, DEL_NONE, Message1 )
	FILE( WRITE_TEXT, hLogFile, DEL_NONE, Message2 )
	FILE( WRITE_TEXT, hLogFile, DEL_NONE, Message3 )
	FILE( WRITE_BYTES, hLogFile, 1, 10 )
	FILE( WRITE_BYTES, hLogFile, 1, 13 )
	FILE( CLOSE, hLogFile )
}

And the log looks like:

Hello log world
What is going on?
String1String2String3

So great success!

My entire log script file looks like this:

vmthread MAIN
{
	CALL( ClearLog )

	CALL( WriteLog, 'Hello log world' )
	CALL( WriteLog, 'What is going on?' )
}

subcall ClearLog
{
	DATA16 hLogFile
	FILE( OPEN_WRITE, 'log12.txt', hLogFile )
	FILE( CLOSE, hLogFile )
}

subcall WriteLog
{
	IN_S	Message		128

	DATA16 hLogFile
	FILE( OPEN_APPEND, 'log12.txt', hLogFile )
	FILE( WRITE_TEXT, hLogFile, DEL_NONE, Message )
	FILE( WRITE_BYTES, hLogFile, 1, 10 )
	FILE( WRITE_BYTES, hLogFile, 1, 13 )
	FILE( CLOSE, hLogFile )
}

I intend to include the log.lms into projects so I can get some logging in.

Having said that, I have recently found the FILE WRITE_LOG function that I’m curios if I should use. Perhaps it is simply writing a unified time stamp to a log file, but there is also a function called FILE OPEN_LOG, which indicates that it is not a regular text log written to a text file but something else. (The documentation explains FILE OPEN_LOG like this, “Create file for data logging (if name starts with ‘~’,’/’ or ‘.’ it is not from current folder) (see \ref cinputsample “Example”)”)

So that is it for me today. I have a fully functional little log code.

Happy coding!

Leave a Reply