Coder Social home page Coder Social logo

luajit-glfw's People

Contributors

colonelthirtytwo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

luajit-glfw's Issues

cdef.py but Lua

I found that it would be good to have cdef.py in Lua.
I maked this one for me:


local function strip(cad)
    return cad:gsub("^%s*(.-)%s*$","%1")
end

local defines = {}
local cdefs = {}

--location_re = '^# \d+ "([^"]*)"'
--glpath_re = '^(?:.*[\\/]|\A)(gl|glu|glfw3|glext)\.h$'
--define_re = "^#define\s+([^\s]+)\s+([^\s]+)$"

location_re = '^# %d+ "([^"]*)"'
glpath_re = '^(.*[\\/])(gl.-)%.h$' --'^(?:.*[\\/]|\A)(gl|glu|glfw3|glext)\.h$'
define_re = "^#define%s+([^%s]+)%s+([^%s]+)$"

number_re = "^-?[0-9]+$"
hex_re = "0x[0-9a-fA-F]+$"

-- Set of known #defines that we don't need to include
INVALID_DEFINES = {GLAPI=1, APIENTRY=1, GLU_TESS_MAX_COORD=1, gluErrorStringWIN=1, WINGDIAPI=1, CALLBACK=1}

local in_gl = false
for line in io.lines() do
repeat -- simulate continue with break

    --print(line)
    line = strip(line)
    if #line == 0 then break end
    -- Is this a preprocessor statement?
    if line:sub(1,1) == "#" then
        -- Is this a location pragma?
        local location_match = line:match(location_re)
        if location_match then
            --print("location_match",line)
            -- If we are transitioning to a header we need to parse, set the flag
            local glpath_match,aaa = location_match:match(glpath_re)
            in_gl = (glpath_match ~= nil)
            --if in_gl then print(aaa) end
            break
        end
        if in_gl then
            local name,val = line:match(define_re)
            if name then 
                --print("define ",name,val)
                if defines[val] then
                    -- Is this an alias of something we have already defined?
                    val = defines[val]
                elseif val:match(number_re) or val:match(hex_re) then
                    defines[name] = val
                elseif val == "0xFFFFFFFFFFFFFFFFull" then
                    -- Fix for GL_TIMEOUT_IGNORED
                    defines[name] = val
                elseif val == "0xFFFFFFFFu" then
                    -- Fix for GL_INVALID_INDEX
                    defines[name] = "0xFFFFFFFF"
                elseif not INVALID_DEFINES[name] then
                    -- Incompatible define
                    print("xxxxxxxxxInvalid define:", name)
                end
                break
            end
        end

    elseif in_gl then
        -- Windows likes to add __stdcall__ to everything, but it isn't needed and is actually harmful when using under linux.
        -- However, it is needed for callbacks in windows.
        --if line:find("typedef") >= 0  and line.find(" PFNGL") < 0:
        if line:find("typedef") and not line:find(" PFNGL") then
            line = line:gsub("__attribute__%(%(__stdcall__%)%) ", 'WINDOWS_STDCALL ')
        else
            line = line:gsub("__attribute__%(%(__stdcall__%)%) ", '')
        end
        -- While linux likes to add __attribute__((visibility("default"))) 
        line = line:gsub('__attribute__%(%(visibility%("default"%)%)%) ', '')
        line = line:gsub("__attribute__%(%(__stdcall__%)%) ", '')
        table.insert(cdefs,line)
    end

until true
end
-- Output the file
    print("--[[ BEGIN AUTOGENERATED SEGMENT ]]")
    print("local glc; do local cdecl = [[")
    for i,line in ipairs(cdefs) do
        io.write("\t", line,"\n") --, sep="")
    end
    print("\t]]; if require('ffi').os == 'Windows' then cdecl = cdecl:gsub('WINDOWS_STDCALL', '__attribute__((__stdcall__))') else cdecl = cdecl:gsub('WINDOWS_STDCALL', '') end; require('ffi').cdef(cdecl); glc = {")

    local defines_keys = {}
    for k,v in pairs(defines) do
        table.insert(defines_keys,k)
    end
    table.sort(defines_keys)
    for i,k in ipairs(defines_keys) do
        --print("\t%s = %s," % ("['"..k.."']", defines[k]))
        print(string.format("\t%s = %s,","['"..k.."']", defines[k]))
    end
    print("} end")
    print("--[[ END AUTOGENERATED SEGMENT ]]")

victor bombi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.