0
0

I recently found about FMOD Ex not providing C++ interface in libfmodex.a for windows, so I wrote a Python script (needs 2.5.1 or higher version) to add implementations to classes of fmod.hpp. It seems to work fine, I hope it will be useful.

[code:3gkrga8u]

This script fixes fmod.hpp file for gcc

FMOD Ex lib for gcc has only C interfaces so we wrap all method calls

import re

FORWARD_RE = r’^ class (?P<class>\w+);$’

CLASS_RE = r’^ class (?P<class>\w+)$’

LINE_RE = r’^ FMOD_RESULT F_API (?P<fname>\w+)(?P<space>\s)\((?P<args>[^)])\);.*’

PARAM_RE = r’(?:const\s+)?(?P<type>(?:unsigned\s+)?\w+)\s+(?P<asterisk>**)(?P<param>\w+)’

forward_re = re.compile(FORWARD_RE)
class_re = re.compile(CLASS_RE)
line_re = re.compile(LINE_RE)
param_re = re.compile(PARAM_RE)

fixed_lines = []
values = {}
fmodex_types = set([’bool’])

f = open(’fmod.hpp’)
for line in f:
fixed_line = line

m = forward_re.match(line)
if m:
    fmodex_types.add(m.group('class'))
else:
    m = class_re.match(line)
    if m:
        fmodex_types.add(m.group('class'))
        values['class'] = m.group('class')

    else:
        m = line_re.match(line)
        if m:
            fname = m.group('fname')
            values['fname'] = fname
            values['fname_cap'] = fname[0].upper() + fname[1:]
            values['space'] = m.group('space')
            values['args']  = m.group('args')

            args_list = re.split(r',\s*', values['args'])

            params_list = ['(FMOD_%s *)this' % values['class'].upper()]            
            params_matches = [param_re.match(arg) for arg in args_list if arg]

            for match in params_matches:
                param_type  = match.group('type')
                asterisk    = match.group('asterisk')
                param_name  = match.group('param')

                if param_type in fmodex_types:
                    cast  = 'FMOD_%s' % param_type.upper()
                    if asterisk:
                        cast += ' %s' % asterisk
                    param = '(%s)%s' % (cast, param_name)
                else:
                    param = param_name

                params_list.append(param)

            values['params'] = ', '.join(params_list)
            fixed_line = '        FMOD_RESULT F_API %(fname)s%(space)s(%(args)s) { return FMOD_%(class)s_%(fname_cap)s(%(params)s); }\n' % values

fixed_lines.append(fixed_line)

f.close()

f = open(’fmod-gcc.hpp’, ‘w’)
f.writelines(fixed_lines)
f.close()

[/code:3gkrga8u]

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.