Class WebView

WebView (htmlAsset) Create a new WebView.
WebView:loadJS (obj, async) Evaluate JavaScript in the current page's JavaScript environment.
WebView:loadHTML (obj) Load HTML content into the WebView Note: This resets the JavaScript environment.
WebView:callAsync (funcName, ...) Call a JavaScript function asynchronously.
WebView:call (funcName, ...) Call a JavaScript function.
WebView:import (name, func) Import Lua functions, tables or values into the JavaScript environment
WebView:proxy (name) Proxies assignments to a JavaScript table of the same name through to the global table of the same name in Lua.
WebView:importJSModule (url, parts, as) Imports a JavaScript ES Module into the JavaScript environment
WebView:show () Display the content of the WebView.
WebView:hide () Hide the content of the WebView.
WebView:enableInputHandling (enabled) Enables or Disables input handling for the WKWebView.

Class WebView

Object representing a single WKWebView.
WebView (htmlAsset)
Create a new WebView.

Parameters:

  • htmlAsset (optional) HTML string or Codea asset to load immediately

Returns:

    new WebView instance

Usage:

  • local webview = WebView()
  • local webview = WebView([[
    <body>
    	Hello World!
    </body>
    ]])
  • local webview = WebView(asset.index_html)
WebView:loadJS (obj, async)
Evaluate JavaScript in the current page's JavaScript environment.

Parameters:

  • obj JavaScript URL, source string or Codea asset containing JavaScript source to evaluate
  • async If true, returns immediately after handing JavaScript to WKWebView. If false, returns only when the JavaScript is fully evaluated. (default false)
WebView:loadHTML (obj)
Load HTML content into the WebView Note: This resets the JavaScript environment.

Parameters:

  • obj HTML source or Codea asset containing HTML source
WebView:callAsync (funcName, ...)
Call a JavaScript function asynchronously.

Parameters:

  • funcName name of the JavaScript function to call
  • ... parameters to provide to the JavaScript function

Returns:

    Promise object that will return the result of the call once complete
WebView:call (funcName, ...)
Call a JavaScript function.

Parameters:

  • funcName name of the JavaScript function to call
  • ... parameters to provide to the JavaScript function

Returns:

    The result of the call
WebView:import (name, func)
Import Lua functions, tables or values into the JavaScript environment Lua userdata types cannot be passed to JavaScript

Parameters:

  • name Name to give to the corresponsing object in JavaScript OR table of key-value pairs representing the values to import.
  • func Function, Value or Table to assign to the given object in JavaScript.

Usage:

  • webview:import("print", function(...)
    	print(...)
    end)
  • webview:import("WIDTH", WIDTH)
  • webview:import("RESOLUTION", {
    	WIDTH = WIDTH,
    	HEIGHT = HEIGHT
    })
  • webview:import("ContentScaleFactor", ContentScaleFactor)
  • webview:import({
    	RESOLUTION = {
    		WIDTH = WIDTH,
    		HEIGHT = HEIGHT
    	},
    	ContentScaleFactor = ContentScaleFactor,
    	print = function(...)
    		print(...)
    	end
    })
WebView:proxy (name)
Proxies assignments to a JavaScript table of the same name through to the global table of the same name in Lua.

Parameters:

  • name Name of the global Lua table to proxy

Usage:

    -- I add a proxy for 'viewer' in JS.
    -- This allows JS code to do the following: viewer.mode = 2; // (for FULLSCREEN)
    webview:proxy(viewer)
WebView:importJSModule (url, parts, as)
Imports a JavaScript ES Module into the JavaScript environment

Parameters:

  • url The URL of the module to import.
  • parts (optional) Array of module exports to be imported.
  • as (optional) Array of names that will refer to the names imports in 'parts' OR string to name entire import.

Usage:

  • webview:importJSModule('https://cdn.skypack.dev/three@0.136.0', nil, 'THREE')
  • webview:importJSModule('https://cdn.skypack.dev/three@0.136.0/examples/jsm/controls/OrbitControls.js', { 'OrbitControls' })
  • -- Rename the exported 'OrbitControls' to 'OrbControls':
    webview:importJSModule('https://cdn.skypack.dev/three@0.136.0/examples/jsm/controls/OrbitControls.js', { 'OrbitControls' }, { 'OrbControls' })
WebView:show ()
Display the content of the WebView.

This places our WKWebView over Codea's OpenGL based EAGLView

WebView:hide ()
Hide the content of the WebView.

This removes our WebView from the UIView hierarchy

WebView:enableInputHandling (enabled)
Enables or Disables input handling for the WKWebView. When input handling is DISABLED, Codea's usual touch & gesture callbacks are still triggered. These can then be passed onto JavaScript as necessary.

When input handling is ENABLED, Codea's usual touch & gesture callbacks are not triggered. This allows the Web content to register its own input handlers as it would in a browser.

Note: By default, input handling is ENABLED

Parameters:

  • enabled true or false
generated by LDoc 1.4.6 Last updated 2022-03-03 16:11:02