Merge pull request #110 from tesselode/fixes
[wdl/wdl-ol.git] / WDL / swell / swell-appstub-generic.cpp
blobd2a2ed759ebfaa686614ebb7764c3a486c5de166
1 /* Cockos SWELL (Simple/Small Win32 Emulation Layer for Linux/OSX)
2 Copyright (C) 2006 and later, Cockos, Inc.
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
21 #include "swell.h"
24 #ifndef SWELL_PROVIDED_BY_APP
26 // only add this file to your project if you are an application that wishes to publish the SWELL API to its modules/plugins
27 // the modules should be compiled using SWELL_PROVIDED_BY_APP and include swell-modstub.mm
29 #undef _WDL_SWELL_H_API_DEFINED_
30 #undef SWELL_API_DEFINE
31 #define SWELL_API_DEFINE(ret, func, parms) {#func, (void *)func },
32 static struct api_ent
34 const char *name;
35 void *func;
37 api_table[]=
39 #include "swell.h"
42 static int compfunc(const void *a, const void *b)
44 return strcmp(((struct api_ent*)a)->name,((struct api_ent*)b)->name);
47 extern "C" {
48 __attribute__ ((visibility ("default"))) void *SWELLAPI_GetFunc(const char *name)
50 if (!name) return (void *)0x100; // version
51 static int a;
52 if (!a)
54 a=1;
55 qsort(api_table,sizeof(api_table)/sizeof(api_table[0]),sizeof(api_table[0]),compfunc);
57 struct api_ent find={name,NULL};
58 struct api_ent *res=(struct api_ent *)bsearch(&find,api_table,sizeof(api_table)/sizeof(api_table[0]),sizeof(api_table[0]),compfunc);
59 if (res) return res->func;
60 return NULL;
64 #endif