diff --git a/sourcepawn/vm/sp_vm.c b/sourcepawn/vm/sp_vm.c index d1c720e5..b795ed06 100644 --- a/sourcepawn/vm/sp_vm.c +++ b/sourcepawn/vm/sp_vm.c @@ -247,5 +247,60 @@ int SP_GetPubVarsNum(sp_context_t *ctx, uint32_t *num) { *num = ctx->plugin->info.pubvars_num; + return SP_ERR_NONE; +} + +int SP_BindNatives(sp_context_t *ctx, sp_nativeinfo_t *natives, unsigned int num, int overwrite) +{ + uint32_t i, j, max; + + max = ctx->plugin->info.natives_num; + + for (i=0; inatives[i].status == SP_NATIVE_OKAY && !overwrite) + continue; + + for (j=0; (natives[j].name) && (!num || jnatives[i].name, natives[j].name)) + { + ctx->natives[i].pfn = natives[j].func; + ctx->natives[i].status = SP_NATIVE_OKAY; + } + } + } + + return SP_ERR_NONE; +} + +int SP_BindNative(sp_context_t *ctx, sp_nativeinfo_t *native, uint32_t status) +{ + uint32_t index, err; + + if ((err = SP_FindNativeByName(ctx, native->name, &index)) != SP_ERR_NONE) + return err; + + ctx->natives[index].pfn = native->func; + ctx->natives[index].status = status; + + return SP_ERR_NONE; +} + +int SP_BindNativeToAny(sp_context_t *ctx, SPVM_NATIVE_FUNC native) +{ + uint32_t nativesnum, i; + + nativesnum = ctx->plugin->info.natives_num; + + for (i=0; inatives[i].status != SP_NATIVE_OKAY) + { + ctx->natives[i].pfn = native; + ctx->natives[i].status = SP_NATIVE_PENDING; + } + } + return SP_ERR_NONE; } \ No newline at end of file diff --git a/sourcepawn/vm/sp_vm.h b/sourcepawn/vm/sp_vm.h index e8a3ae68..bba01c79 100644 --- a/sourcepawn/vm/sp_vm.h +++ b/sourcepawn/vm/sp_vm.h @@ -240,7 +240,7 @@ int SP_PushCellsFromArray(sp_context_t *ctx, cell_t array[], unsigned int numcel * Binds a list of native names and their function pointers to a context. * If num is 0, the list is read until an entry with a NULL name is reached. * All natives are assigned a status of SP_NATIVE_OKAY by default. - * If overwrite is non-zero, already registered arrays will be overwritten. + * If overwrite is non-zero, already registered natives will be overwritten. * * @param ctx Context pointer. * @param natives Array of natives. @@ -250,6 +250,8 @@ int SP_BindNatives(sp_context_t *ctx, sp_nativeinfo_t *natives, unsigned int num /** * Binds a single native. Overwrites any existing bind. + * If the context does not contain the native that will be binded the function will return + * with a SP_ERR_NOT_FOUND error. * * @param ctx Context pointer. * @param native Pointer to native. @@ -263,7 +265,7 @@ int SP_BindNative(sp_context_t *ctx, sp_nativeinfo_t *native, uint32_t status); * * @param ctx Context pointer. */ -int SP_BindNativeToAny(sp_context_t *ctx, sp_nativeinfo_t *native); +int SP_BindNativeToAny(sp_context_t *ctx, SPVM_NATIVE_FUNC native); /** * Executes a public function in a context.