from functools import wraps
from FFI import *
from glob import glob

LIB_PATH = '/usr/lib/'


def load_lib(api=None):
    global ffi
    if api == "GLX":
        api = api[:-1]
    for f in glob(LIB_PATH + '/lib{}*.so.*.*'.format(api)):
        dl_lib = f
    ffi = globals()["_" + api.lower().replace('v', '') + "ffi"].ffi
    return ffi, ffi.dlopen(dl_lib)

def params(*largs):
    def deco(func):
        @wraps(func)
        def wrap(*args):
            varn = func.__code__.co_varnames
            prms = list(largs)
            retdict = {}
            f = getattr(lib, func.__name__)
            for inx, p in enumerate(largs):
                for i, a in enumerate(varn):
                    if a == p:
                        prms[inx] = args[i]
                if p not in varn:
                    if p in ffinew_retlist:
                        retdict[p] = inx
                    p = ffi.new(ffi.typeof(f).args[inx].cname)
                    prms[inx] = p
            r = f(*prms)
            if len(retdict) > 0:
                for k, v in retdict.items():
                    retdict[k] = prms[v][0]
                return retdict
            else:
                return r
        return wrap
    return deco
@@ -1,12 +1,27 @@
+import os, sys%0A
 from functoo
@@ -75,16 +75,53 @@
 ort glob
+%0Afrom ctypes.util import find_library
 %0A%0ALIB_PA
@@ -137,16 +137,26 @@
 r/lib/'%0A
+libs = %7B%7D%0A
 %0A%0Adef lo
@@ -181,141 +181,65 @@
     
-global ffi
+'''
 %0A    
-if 
 api
- == %22GLX%22:%0A        api = api%5B:-1%5D%0A    for f in glob(LIB_PATH + '/lib%7B%7D*.so.*.*'.format(api)):%0A        dl_lib = f
+'s are EGL, GL, GLESv2, GLESv1_CM, GLX%0A    '''
 %0A   
@@ -334,17 +334,29 @@
 pen(
-dl_lib
+find_library(api)
 )%0A%0A
+%0A
 def 
@@ -364,24 +364,35 @@
 arams(*largs
+, **lkwargs
 ):%0A    def d
@@ -394,16 +394,21 @@
 def deco
+rator
 (func):%0A
@@ -444,16 +444,19 @@
 def wrap
+per
 (*args):
@@ -557,16 +557,80 @@
 ct = %7B%7D%0A
+            api = lkwargs%5B'api'%5D%0A            ffi = libs%5Bapi%5D%5B1%5D%0A
         
@@ -648,16 +648,25 @@
 attr(lib
+s%5Bapi%5D%5B0%5D
 , func._
@@ -904,22 +904,20 @@
  in 
-ffinew_retlist
+libs%5Bapi%5D%5B2%5D
 :%0A  
@@ -1292,16 +1292,19 @@
 urn wrap
+per
 %0A    ret
@@ -1307,12 +1307,18 @@
  return deco
+rator%0A

Update __init__.py