Add Lua 5.3 support

This commit is contained in:
gamax92 2016-01-16 12:03:25 -07:00
parent 0173be5116
commit 4e870aec70
6 changed files with 26 additions and 11 deletions

View File

@ -4,7 +4,7 @@ OCEmu - OpenComputers Emulator
Installation Installation
------------ ------------
Needs lua-5.2, luafilesystem, utf8, luaffi, and SDL2. Needs lua-5.2, luafilesystem, luautf8, luaffi, and SDL2.
luasocket is optional but is required for the Internet Component and higher precision timing. luasocket is optional but is required for the Internet Component and higher precision timing.
@ -38,7 +38,7 @@ Follow the luarocks steps below.
**Lua Libraries** **Lua Libraries**
``` ```
luarocks-5.2 install luafilesystem luarocks-5.2 install luafilesystem
luarocks-5.2 install utf8 luarocks-5.2 install luautf8
luarocks-5.2 install luasocket luarocks-5.2 install luasocket
luarocks-5.2 install luasec luarocks-5.2 install luasec
luarocks-5.2 install --server=http://luarocks.org/dev luaffi luarocks-5.2 install --server=http://luarocks.org/dev luaffi

View File

@ -1,6 +1,6 @@
local env = ... local env = ...
local utf8 = require("utf8") local utf8 = require("lua-utf8")
local function cln(str) local function cln(str)
return str:gsub("%z.*","") .. "" return str:gsub("%z.*","") .. ""

View File

@ -3,7 +3,7 @@ compCheckArg(1,maxwidth,"number")
compCheckArg(2,maxheight,"number") compCheckArg(2,maxheight,"number")
compCheckArg(3,maxtier,"number") compCheckArg(3,maxtier,"number")
local lua_utf8 = require("utf8") local utf8 = require("lua-utf8")
local bindaddress local bindaddress
local depthTbl = {1,4,8} local depthTbl = {1,4,8}
@ -102,7 +102,7 @@ function obj.fill(x, y, width, height, char) -- Fills a portion of the screen at
if bindaddress == nil then if bindaddress == nil then
return nil, "no screen" return nil, "no screen"
end end
if lua_utf8.len(char) ~= 1 then if utf8.len(char) ~= 1 then
return nil, "invalid fill value" return nil, "invalid fill value"
end end
return component.cecinvoke(bindaddress, "fill", x, y, width, height, char) return component.cecinvoke(bindaddress, "fill", x, y, width, height, char)

View File

@ -1,7 +1,7 @@
local address = ... local address = ...
local ffi = require("ffi") local ffi = require("ffi")
local lua_utf8 = require("utf8") local utf8 = require("lua-utf8")
local SDL = elsa.SDL local SDL = elsa.SDL
-- Conversion table for SDL2 keys to LWJGL key codes -- Conversion table for SDL2 keys to LWJGL key codes
@ -18,7 +18,7 @@ function elsa.textinput(event)
local textevent = ffi.cast("SDL_TextInputEvent*", event) local textevent = ffi.cast("SDL_TextInputEvent*", event)
local text = ffi.string(textevent.text) local text = ffi.string(textevent.text)
cprint("textinput",text) cprint("textinput",text)
setLatest(lua_utf8.byte(text)) setLatest(utf8.byte(text))
end end
function elsa.keydown(event) function elsa.keydown(event)

View File

@ -4,7 +4,7 @@ compCheckArg(2,maxheight,"number")
compCheckArg(3,maxtier,"number") compCheckArg(3,maxtier,"number")
local ffi = require("ffi") local ffi = require("ffi")
local utf8 = require("utf8") local utf8 = require("lua-utf8")
local bit = require("bit32") local bit = require("bit32")
local SDL = elsa.SDL local SDL = elsa.SDL

View File

@ -124,7 +124,6 @@ local env = {
upvalueid = debug.upvalueid, upvalueid = debug.upvalueid,
upvaluejoin = debug.upvaluejoin, upvaluejoin = debug.upvaluejoin,
}, },
dofile = dofile,
error = error, error = error,
getmetatable = getmetatable, getmetatable = getmetatable,
io = { io = {
@ -145,7 +144,6 @@ local env = {
}, },
ipairs = ipairs, ipairs = ipairs,
load = load, load = load,
loadfile = loadfile,
math = { math = {
abs = math.abs, abs = math.abs,
acos = math.acos, acos = math.acos,
@ -166,7 +164,7 @@ local env = {
max = math.max, max = math.max,
min = math.min, min = math.min,
modf = math.modf, modf = math.modf,
pi = 3.1415926535898, pi = math.pi,
pow = math.pow, pow = math.pow,
rad = math.rad, rad = math.rad,
random = math.random, random = math.random,
@ -230,6 +228,23 @@ local env = {
type = type, type = type,
xpcall = xpcall, xpcall = xpcall,
} }
if _VERSION == "Lua 5.3" then
env._VERSION = "Lua 5.3"
env.coroutine.isyieldable = coroutine.isyieldable
env.math.maxinteger = math.maxinteger
env.math.mininteger = math.mininteger
env.math.tointeger = math.tointeger
env.math.type = math.type
env.math.ult = math.ult
env.string.pack = string.pack
env.string.packsize = string.packsize
env.string.unpack = string.unpack
env.table.move = table.move
env.utf8 = {}
for k,v in pairs(utf8) do
env.utf8[k] = v
end
end
setmetatable(env,{ setmetatable(env,{
__index = function(_,k) __index = function(_,k)
cprint("Missing environment access", "env." .. k) cprint("Missing environment access", "env." .. k)