Automatic initialisation of primitives.

Started by
2 comments, last by ac8 3 weeks, 1 day ago

Specifically, I would like to have any newly created variables be initialised to 0. I'm curious if this is something that would be possible to accomplish fairly easily perhaps?

I've been looking around in the source for a while, but I'm having a bit of trouble figuring out exactly what I need to do to accomplish this, if it is even possible.

Advertisement

Yes, this can be done. There are basically two ways:

1) Change the compiler to emit bytecode to clear the variables if they are read before being initialized. This is a more complex as it requires going into the details of the compiler to add logic to identify which variables actually require being cleared, to avoid adding unecessary bytecode which would just slow down the performance (and consume more memory).

2) Change asCContext::PrepareScriptFunction to clear the entire stack frame, rather than just the object variables. This option should be quite easy to implement. This would not take care of variables within loops, that should ideally be reset with each iteration.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

@WitchLord The second option seemed perfect for this use case (attempting to get it to read scripts in a language that was very heavily based on C), and seems to be working out. Thank you very much for your help!

Advertisement