JS engine stuff

Want to discuss changes to the UOX3 source code? Got a code-snippet you'd like to post? Anything related to coding/programming goes here!
Post Reply
xir
Has thanked: 0
Been thanked: 0

JS engine stuff

Post by xir »

I'm having a look to try and get the File I/O working. I'm currently working through with the documentation and if anyone wants to feel free to give me some pointers go ahead. :twisted:

Ok firstly there is something wrong with the initialisation of custom classes.

Code: Select all

GumpProto			=	JS_InitClass( targContext, targObject, targObject, &UOXGump_class, Gump, 0, NULL, CGump_Methods, NULL, CGump_Methods );
I'm taking this as an example

We only care about the last four parameters:
my_props, my_methods,
my_static_props, my_static_methods

CGump_Methods is a static array that holds function pointers (as callbacks) to the custom object.

For example if you want to create a gump you would do
var myGump = new Gump;

If you want to add a page to a gump you would do
myGump.AddPage(0);

These are "instance" functions which relate to the object.

However the exact same array is passed into "my_static_methods" parameter. Static methods are quite different than instance functions as I'm sure everyone is aware which would allow this.

Gump.AddPage(0);

This statement gets parsed fine by the javascript engine but when executes it obviously crashes. I've changed this to test the UOXCFile and it throws an error now, but it still doesn't fix the File I/O :(

The same applies to the "my_props" and "my_static_props" parameters too. All the custom objects are not declared correctly and this needs fixing. I'm not 100% on which methods/properties are static and which are not. I presume most of them are instance though.

This is also the case with the UOXCFile but it still doesn't fix it so the search continues :)
xir
Has thanked: 0
Been thanked: 0

Post by xir »

Ok well what the problem with the FILE I/O is the UOXCFile constructor gets called but the Methods don't get called.
xir
Has thanked: 0
Been thanked: 0

Post by xir »

Ok I got the File I/O working in a round about way.

Code: Select all

UOXCFileProto		=	JS_InitClass( targContext, targObject, targObject, &UOXFile_class, UOXCFile, 0, CFileProperties, NULL, NULL, NULL );

	JS_DefineFunction( targContext, targObject, "Open", CFile_Open, 2, 0);
	JS_DefineFunction( targContext, targObject, "Write", CFile_Write, 1, 0);
	JS_DefineFunction( targContext, targObject, "Close", CFile_Close, 0, 0);
	JS_DefineFunction( targContext, targObject, "Free", CFile_Free, 0, 0);
	JS_DefineFunction( targContext, targObject, "Read", CFile_Read, 1, 0);
	JS_DefineFunction( targContext, targObject, "ReadUntil", CFile_ReadUntil, 1, 0);
I just defined the functions explicitly instead of using the method list array in the JS_InitClass(). I don't know know why the method array doesn't work though which I am inspecting now. :x
xir
Has thanked: 0
Been thanked: 0

Post by xir »

JS_DefineFunctions( targContext, targObject, CFile_Methods);

instead of the JS_DefineFunction() junk :P

Now I know ther array is working I suspect its something to do with the JS_InitClass parameters. Some parameter must bypass the checking of the CFile_Methods array.

*continues*
xir
Has thanked: 0
Been thanked: 0

Post by xir »

I can't find out why the JS_InitClass() won't except the CFile_Methods array. All the other JS_InitClass() seem to work using the exact same approach, so I give up.
The solution is this to get the JS File I/O working

Code: Select all

UOXCFileProto		=	JS_InitClass( targContext, targObject, targObject, &UOXFile_class, UOXCFile, 0, CFileProperties, NULL, NULL, NULL );
JS_DefineFunctions( targContext, targObject, CFile_Methods);
around line 200 in cScript.cpp

If anyone knows why the JS_InitClass() is acting up let me know, I'd be interested :P
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

As for why it's having issues, that's a good question...

I do know that it was giving me problems as well. I was attempting to modify a class to add methods to it (much the same as you are trying to do with CFile) and it would not only fail to work, it would crash every time I attempted to use the methods (or the class at all).

It could quite possibly be due to the size constraint (which Maarc just recently increased). Otherwise, it's simply an issue we are going to have to work on fixing.
Scott
Post Reply