示例#1
0
def generate_callback(file, func):
    params = ', '.join(
        ['%s %s' % (C_TYPES[x.type], x.name) for x in func.params])

    file.write('PLUGIN_EXPORT bool PLUGIN_CALL %s(%s) {\n' %
               (func.name, params))
    file.write('  return ufs::UFS::Instance().ForEachScript(')

    badret = func.get_attr('badret', cidl.Value('bool', False))
    defret = ('false', 'true')[not badret.value.data]
    args = ', '.join([p.name for p in func.params])

    file.write('ufs::%s(%s), %s);\n' % (func.name, args, defret))
    file.write('}\n\n')
示例#2
0
def generate_callback_class(file, func):
    file.write('class %s {\n' % func.name)
    file.write(' public:\n')

    if len(func.params) > 0:
        file.write('  %s(%s): %s {}\n' % (
            func.name,
            ', '.join([
                '%s %s' % (idl_to_c_type[p.type], p.name) for p in func.params
            ]),
            ', '.join(['%s_(%s)' % (p.name, p.name) for p in func.params]),
        ))
    else:
        file.write('  %s() {}\n' % func.name)

    file.write('  bool operator()(Script *s) {\n')

    for p in reversed(func.params):
        if p.type == 'string':
            file.write('    cell %s_addr;\n' % p.name)
            file.write(
                '    amx_PushString(s->amx(), &%s_addr, 0, %s_, 0, 0);\n' %
                (p.name, p.name))
        elif p.type == 'float':
            file.write('    amx_Push(s->amx(), amx_ftoc(%s_));\n' % p.name)
        else:
            file.write('    amx_Push(s->amx(), %s_);\n' % p.name)

    badret = func.get_attr('badret', cidl.Value('bool', False))
    defret = ('false', 'true')[not badret.value.data]

    if len(func.params) > 0:
        file.write('    bool ret = s->Exec("%s", %s);\n' % (func.name, defret))
        for p in func.params:
            if p.type == 'string':
                file.write('    amx_Release(s->amx(), %s_addr);\n' % p.name)
        file.write('    return ret;\n')
    else:
        file.write('    return s->Exec("%s", %s);\n' % (func.name, defret))

    file.write('  }\n')

    file.write(' private:\n')
    for p in func.params:
        file.write('  %s %s_;\n' % (idl_to_c_type[p.type], p.name))
    file.write('};\n\n')
示例#3
0
def generate_source(file, idl):
    file.write('#include <sampgdk/a_objects.h>\n')
    file.write('#include <sampgdk/a_players.h>\n')
    file.write('#include <sampgdk/a_samp.h>\n')
    file.write('#include <sampgdk/a_vehicles.h>\n')
    file.write('#include <sampgdk/core.h>\n')
    file.write('#include <sampgdk/sdk.h>\n\n')

    file.write('extern void *pAMXFunctions;\n\n')

    file.write('PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {\n')
    file.write(
        '  return sampgdk::Supports() | SUPPORTS_AMX_NATIVES | SUPPORTS_PROCESS_TICK;\n'
    )
    file.write('}\n\n')

    file.write('PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) {\n')
    file.write('  pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];\n')
    file.write('  return sampgdk::Load(ppData);\n')
    file.write('}\n\n')

    file.write('PLUGIN_EXPORT void PLUGIN_CALL Unload() {\n')
    file.write('}\n\n')

    file.write('PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *amx) {\n')
    file.write('  return AMX_ERR_NONE;\n')
    file.write('}\n\n')

    file.write('PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX *amx) {\n')
    file.write('  return AMX_ERR_NONE;\n')
    file.write('}\n\n')

    file.write('PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {\n')
    file.write('  sampgdk::ProcessTick();\n')
    file.write('}\n\n')

    for c in get_callbacks(idl):
        params = ['%s %s' % (C_TYPES[x.type], x.name) for x in c.params]
        file.write('PLUGIN_EXPORT bool PLUGIN_CALL %s(%s) {\n' %
                   (c.name, ', '.join(params)))
        badret = c.get_attr('badret', cidl.Value('bool', False))
        file.write('  return %s;\n' % ('false', 'true')[not badret.value.data])
        file.write('}\n\n')