2.16 Differences between Hollywood and Lua

If you plan to write plugins that extend Hollywood's script language by installing new commands and constants, you will have to deal with the Lua VM which is at the heart of Hollywood. Hollywood uses Lua 5.0.2 as its virtual machine but with major modifications. Here is a non-exhaustive list of the differences between Lua 5.0.2 and Hollywood:

  1. At a first glance, Hollywood in contrast to Lua does not seem to distinguish between lower and upper case characters for keywords, preprocessor commands, variable, function, and constant names. You can mix upper and lower case characters any way you please. Internally, however, Hollywood still does the distinction between upper and lower case in true Lua fashion. The reason why you don't notice this, is because Hollywood's parser converts everything to lower case when it parses your script so all the differences are levelled at parsing time already and you don't have to care about upper and lower case characters when writing your script. However, if you write a plugin and you push elements into the stack or pop them from the stack, you need to be very careful that you use lower case strings only when describing these elements. Otherwise the user won't be able to access the elements that you have pushed or you won't be able to access the elements the user has pushed because internally Hollywood still distinguishes between upper and lower case characters. This must be kept in mind when writing plugins that push/pop stack elements. Always use lower case characters for everything and your plugin will fit in just fine.

  2. The handling of Nil is different between Hollywood and Lua. Comparing 0 against Nil will be True in Hollywood, but False in Lua. This change has been made to allow you to work with uninitialiazed variables. If you pass an uninitialized, i.e. a Nil variable to a function or you use an uninitialized variable in an equation, Hollywood will just treat this uninitialized variable as if its value was 0. Lua, on the other hand, will fail if you try do arithmetics with Nil variables or pass a Nil variable to a function which expects a numerical value. Hollywood will just assume a numerical value of 0 for all uninitialized variables. The only exception from this rule is with table elements. Hollywood will fail if you try to index table elements that are Nil. It will not automatically assume 0 for them. That is why you have to explicitly initialize all table elements you want to use. Variables, on the other hand, don't have to be initialized explicitly. You can just use them and if they are still Nil, Hollywood will assume they are 0.

  3. Hollywood does not support the boolean object type. In Hollywood, the values True and False are simply special constants that will be mapped to the numerical values 1 and 0 respectively. There is no special object type for boolean values. This means that comparing 0 against False will be True in Hollywood, whereas in Lua it would be False because you would be comparing two different object types. Internally, Lua's boolean API is still supported by the VM and your plugin could use the respective functions from LuaBase but this is not recommended since Hollywood itself will never use Lua's boolean object type. It will always just use numbers. Not to mention that it is impossible to pass a real Lua boolean value to one of your plugin's functions because the parser will map all the True and False keywords to plain numbers.

  4. The syntax is different. Whereas Lua uses the end keyword to close all kinds of different scopes, Hollywood has scope-dependent closing keywords like Wend, Next, EndIf and so on to make script files better readable.

  5. The operators are different. For example, Lua uses ~= for the not equal operator whereas Hollywood uses <>. Hollywood also supports much more operators than Lua does. For example, Hollywood comes with a variety of bitwise operators that Lua is missing entirely.

  6. Lua uses 1-based tables and arrays whereas in Hollywood they are 0-based as in almost every other programming language. Though 1-based arrays might make more sense from a strictly logical point of view, 0-based arrays are the de facto standard in the programming world.

  7. Hollywood's preprocessor has support for preprocessor commands, e.g. @BRUSH or @INCLUDE. Preprocessor commands are prefixed by the at character (@).

  8. Hollywood supports constants. Constants are always prefixed by the hash tag (#).

  9. Hollywood supports additional program flow statements like Repeat/Until and Switch/EndSwitch.

  10. Hollywood still supports labels and Goto() and Gosub(), although this is considered obsolete and is only included for compatibility with Hollywood 1.x.

  11. Hollywood has a continue statement.

  12. Hollywood introduces a new data type named lua_ID and the functions luaL_checkid() and luaL_checknewid() to deal with its object identifiers. See Object identifiers for details.

  13. There is a difference in the error handling when writing C functions that are callable from Lua. If an error occurs in a C function with Lua 5.0.2, your C function has to call the luaL_error() function which will directly jump to Lua's error handler. In Hollywood, however, you have to return an error code from your C function to indicate that an error has occurred. If that is not possible for some reason, you may also call lua_throwerror() to jump directly into Hollywood's error handler but the recommended way is returning an error code. The reason for this design is that working with error codes is preferable to doing a longjmp() because it gives your code a chance to free resources before it error-exits. Note that Lua functions like luaL_checklstring() and luaL_checknumber() will still jump into the error handler directly, so be prepared to deal with this.

See Library plugins for details.

See LuaBase for details.

Show TOC