zeta0134 / LuaGB

A gameboy emulator written in pure Lua. Work in progress.
BSD 3-Clause "New" or "Revised" License
410 stars 33 forks source link

Easy FFI optimizations #12

Open meepen opened 6 years ago

meepen commented 6 years ago

The MMU for the core of this project currently uses a lua array lookup of bytes, and because of this, it would be super easy to add ffi support (if available - we can always fallback to default lua if it's not available)

local ffi = require "ffi"
if (ffi) then
    function loadarray(narr)
        return ffi.new("uint8_t[?]", narr
    end
else -- no ffi
    function loadarray(narr)
        local t = {}
        for i = 0, narr - 1 do
            t[i] = 0
        end
    end
end

This would have no downsides and is super easy to implement! Was wondering what you thought of these kinds of optimizations? It'd work even if FFI wasn't available and it'd work better if it was.