Skip to content

Lua compatibily

caioviel edited this page Sep 4, 2012 · 8 revisions

There are some limitations in the WebNCL support for Lua scripts. Some of those limitations will be addressed in future versions of WebNCL; other limitations are more complex to solve given javascript's restrictions or the approach used for running Lua script.

In this page are listed limitations and workarounds that can be used to solve then.

NCLua API


event module

For a description of event module, see this page. (in portuguese).

Only the events of class tcp are not implemented yet.

canvas module

For a description of canvas module, see this page. (in portuguese).

All the methods of canvas module presented in the page above are implemented.

persistent module

All the methods of persistent module are implemented.

settings module:

All the methods of settings module are implemented, but not all the possible settings.

Preloading Resources


Loading images and fonts in Lua Scripts is a synchronous task, but it is asynchronous in javascript. Because of this difference, it may be necessary preloading the used resources before execute the Lua scripts.

For preform the preloading, we recommend the use of PxLoader. It has support for preloading images, videos and audios. For fonts, we developed a plug-in for PxLoader.

See a sample of how to use PxLoader.

var myPlayer = new WebNclPlayer("sample/sample-control-lua.ncl","myPlayer");
var loader = new PxLoader();
loader.addImage('test_lua/image1.png');
loader.addImage('test_lua/image2.png');
loader.addFont('garamond','sample/EBGaramond08-Regular.ttf');
loader.addFont('times','sample/times-Regular.ttf');
loader.addCompletionListener(
   function() {	
	 myPlayer.start();
   });
loader.start();

Using Lua require


Currently the WebNCL does not support lua require primitive.

Coroutine


Given the single thread characteristic of javascript language, WebNCL does not support Lua Coroutine.

Although you can simulate coroutines with timers or other mechanism easily.

Other Issues


Here are some important differences between the Lua C and the current implementation of lua.js:

  • A 'NaN' value is equivalment to false in Lua C, but is a true for lua.js

Clone this wiki locally