HttpWrite: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Reverted: Direct call to JS getRandomQuote was not wrong. That's what the ajax resource is for.)
Line 32: Line 32:
   </head>
   </head>
   <body>
   <body>
       <b>Random quote:</b> <* httpWrite( call ( getThisResource(), "getRandomQuote" ) ) *>
       <b>Random quote:</b> <* httpWrite( getRandomQuote() ) *>
   </body>
   </body>
</html>
</html>

Revision as of 13:53, 26 October 2007

This function adds text to the output of the current HTML file of the HTTP interface.

Syntax

bool httpWrite ( string text )

Shortcut syntax

The following shortcut syntax is also supported:

[html]
<* = text *>

which is equivalent to:

[html]
<* httpWrite(text) *>

Required Arguments

  • text: the string of text to be added to the page's output.

Returns

Returns true if the text was added to the output buffer successfully, false otherwise.

Example

This sample resource page will output a random quote from a player using a function previously exported to http from a Lua script in the resource.

[html]
<html>
   <head>
      <* = call ( getResourceFromName("ajax"), "start", getResourceName(getThisResource()) ) *>
   </head>
   <body>
      <b>Random quote:</b> <* httpWrite( getRandomQuote() ) *>
   </body>
</html>

The first httpWrite call (in shortcut syntax) adds the links to scripts generated by the ajax resource, enabling use of the getRandomQuote function.

The second httpWrite call writes the quote generated by the function to the HTML output.

See Also

These functions can only be used from within lua blocks in HTML pages hosted by the server