Adobe 38040334 - Dreamweaver CS3 User Manual page 352

Extending dreamweaver
Hide thumbs Also See for 38040334 - Dreamweaver CS3:
Table of Contents

Advertisement

</FORM>
</BODY>
</HTML>
The
readContentsOfFile()
reads the contents of the file, and returns the contents of the file. For more information about the JavaScript data
structures and functions that appear in the
JavaScript interpreter" on page 347.
JSBool
readContentsOfFile(JSContext *cx, JSObject *obj, unsigned int ¬
argc, jsval *argv, jsval *rval)
{
char *fileName, *fileContents;
JSBool success;
unsigned int length;
/* Make sure caller passed in exactly one argument. If not,
* then tell the interpreter to abort script execution.*/
if (argc != 1){
JS_ReportError(cx, "Wrong number of arguments", 0);
return JS_FALSE;
}
/* Convert the argument to a string */
fileName = JS_ValueToString(cx, argv[0], &length);
if (fileName == NULL){
JS_ReportError(cx, "The argument must be a string", 0);
return JS_FALSE;
}
/* Use the string (the file name) to open and read a file */
fileContents = exerciseLeftToTheReader(fileName);
/* Store file contents in rval, which is the return value passed
* back to the caller */
success = JS_StringToValue(cx, fileContents, 0, *rval);
free(fileContents);
/* Return true to continue or false to abort the script */
return success;
}
To ensure that the
readContentsOfFile()
must register the function with the JavaScript interpreter by including a
Dreamweaver loads the library at startup, it calls the
mation:
• The JavaScript name of the function
• A pointer to the function
• The number of arguments that the function expects
The following example shows how the
function accepts a list of arguments from the user, retrieves the filename argument,
readContentsOfFile()
function executes properly and doesn't cause a JavaScript error, you
MM_Init()
function for the library
MM_Init()
function, see "C-level extensibility and the
function in your library. When
MM_Init()
function to get the following three pieces of infor-
might look:
myLibrary
DREAMWEAVER CS3
346
Extending Dreamweaver

Advertisement

Table of Contents
loading

This manual is also suitable for:

Dreamweaver cs3

Table of Contents