Lua Compatibility
Provides Lua 5.4 functions for Lua 5.2 scripting
Category: Script Writing
Published: Sep 12 2023, 06:57
Last Edited: Sep 12 2023, 06:57
Created for Moho Version: 13.5
Returned Version: 0
Edition Downloads: 955
Version 1.01 2nd May 2023
How to use this file.
=====================
Copy this file to the Custom Content / Scripts / Utility folder.
In any script that needs to run in both Lua 5.4 and Lua 5.2 (i.e. Moho 14 and previous versions) include a call to:
HS_LuaCompatibility ()
Ideally this should be in any "run once" code (e.g. LoadPrefs or Run) but others such as IsRelevant will also work.
The concept is that code developed for Lua 5.2 will run unchanged apart from the inclusion of the call to HS_LuaCompatibility ()
If a script is intended to be run in only a Lua 5.2 or a Lua 5.4 environment, this script is unnecessary.
More information
================
This file contains functions that have been developed to allow scripts to run in Moho 14 (Lua 5.4) and earlier versions of Moho (Lua 5.2)
It will be updated in response to any bugs and to address any other compatibility issues that can be resolved in this way.
The intention is to allow bit32.xxx and the deprecated math.atan2 and math.pow calls to be usable in a Lua 5.4 environment.
This is a transitionary service and will be deprecated once there is no significant user base for Moho 13.5 (i.e. Lua 5.2) and earlier versions.
Scripts developed only for Moho 14 or later should use the Lua 5.4 functions directly.
About Bitwise operations
========================
http://www.lua.org/manual/5.2/manual.html#6.7 describes the set of bit32 functions. Note that they, and the replacement functions here, work on 32 bit integers.
http://www.lua.org/manual/5.4/manual.html#3.4.2 describes the bitwise operators. Note that these are intended for 64 bit integers.
for completeness, this is the list of Moho bitwise functions:
MOHO.bit(p)
MOHO.hasbit(x, p) -- Typical call: if hasbit(x, bit(3)) then ...
MOHO.setbit(x, p)
MOHO.clearbit(x, p)
The bit32 functions and their corresponding bitwise operations are:
band -- a & b & ...
bnot -- ~a
bor -- a | b | ...
bxor -- a ~ b ~ ...
btest -- band (...) ~= 0
lshift -- a << n (if n<0 this shifts right; if n>0 this shifts left)
rshift -- a >> n (if n>0 this shifts right; if n<0 this shifts left)
arshift -- a >> n (if n>0 this shifts right; if n<0 this shifts left)
extract -- no direct replacement
replace -- no direct replacement
lrotate -- no direct replacement
rrotate -- no direct replacement
How to use this file.
=====================
Copy this file to the Custom Content / Scripts / Utility folder.
In any script that needs to run in both Lua 5.4 and Lua 5.2 (i.e. Moho 14 and previous versions) include a call to:
HS_LuaCompatibility ()
Ideally this should be in any "run once" code (e.g. LoadPrefs or Run) but others such as IsRelevant will also work.
The concept is that code developed for Lua 5.2 will run unchanged apart from the inclusion of the call to HS_LuaCompatibility ()
If a script is intended to be run in only a Lua 5.2 or a Lua 5.4 environment, this script is unnecessary.
More information
================
This file contains functions that have been developed to allow scripts to run in Moho 14 (Lua 5.4) and earlier versions of Moho (Lua 5.2)
It will be updated in response to any bugs and to address any other compatibility issues that can be resolved in this way.
The intention is to allow bit32.xxx and the deprecated math.atan2 and math.pow calls to be usable in a Lua 5.4 environment.
This is a transitionary service and will be deprecated once there is no significant user base for Moho 13.5 (i.e. Lua 5.2) and earlier versions.
Scripts developed only for Moho 14 or later should use the Lua 5.4 functions directly.
About Bitwise operations
========================
http://www.lua.org/manual/5.2/manual.html#6.7 describes the set of bit32 functions. Note that they, and the replacement functions here, work on 32 bit integers.
http://www.lua.org/manual/5.4/manual.html#3.4.2 describes the bitwise operators. Note that these are intended for 64 bit integers.
for completeness, this is the list of Moho bitwise functions:
MOHO.bit(p)
MOHO.hasbit(x, p) -- Typical call: if hasbit(x, bit(3)) then ...
MOHO.setbit(x, p)
MOHO.clearbit(x, p)
The bit32 functions and their corresponding bitwise operations are:
band -- a & b & ...
bnot -- ~a
bor -- a | b | ...
bxor -- a ~ b ~ ...
btest -- band (...) ~= 0
lshift -- a << n (if n<0 this shifts right; if n>0 this shifts left)
rshift -- a >> n (if n>0 this shifts right; if n<0 this shifts left)
arshift -- a >> n (if n>0 this shifts right; if n<0 this shifts left)
extract -- no direct replacement
replace -- no direct replacement
lrotate -- no direct replacement
rrotate -- no direct replacement