Add a script function to be executed during the update.
| 872 | |
| 873 | // Add a script function to be executed during the update. |
| 874 | s32 execFunc(FunctionHandle funcHandle, s32 argCount, const ScriptArg* arg) |
| 875 | { |
| 876 | s32 id = -1; |
| 877 | if (!funcHandle) { return id; } |
| 878 | asIScriptFunction* func = (asIScriptFunction*)funcHandle; |
| 879 | |
| 880 | // Get a free context. |
| 881 | asIScriptContext* context = s_engine->RequestContext(); |
| 882 | if (!context) |
| 883 | { |
| 884 | // ERROR |
| 885 | return id; |
| 886 | } |
| 887 | // Then prepare it for execution. |
| 888 | s32 res = context->Prepare(func); |
| 889 | if (res < 0) |
| 890 | { |
| 891 | s_engine->ReturnContext(context); |
| 892 | return id; |
| 893 | } |
| 894 | // Set arguments. |
| 895 | argCount = std::min(argCount, (s32)func->GetParamCount()); |
| 896 | for (s32 i = 0; i < argCount; i++) |
| 897 | { |
| 898 | switch (arg[i].type) |
| 899 | { |
| 900 | case ARG_S32: |
| 901 | { |
| 902 | context->SetArgDWord(i, *((asDWORD*)&arg[i].iValue)); |
| 903 | } break; |
| 904 | case ARG_U32: |
| 905 | { |
| 906 | context->SetArgDWord(i, arg[i].uValue); |
| 907 | } break; |
| 908 | case ARG_F32: |
| 909 | { |
| 910 | context->SetArgFloat(i, arg[i].fValue); |
| 911 | } break; |
| 912 | case ARG_BOOL: |
| 913 | { |
| 914 | context->SetArgByte(i, arg[i].bValue ? 1 : 0); |
| 915 | } break; |
| 916 | case ARG_OBJECT: |
| 917 | { |
| 918 | context->SetArgObject(i, arg[i].objPtr); |
| 919 | } break; |
| 920 | case ARG_STRING: |
| 921 | { |
| 922 | context->SetArgObject(i, (void*)&arg[i].stdStr); |
| 923 | } break; |
| 924 | case ARG_FLOAT2: |
| 925 | { |
| 926 | float2 f2(arg[i].float2Value.x, arg[i].float2Value.z); |
| 927 | context->SetArgObject(i, (void*)&f2); |
| 928 | } break; |
| 929 | case ARG_FLOAT3: |
| 930 | { |
| 931 | float3 f3(arg[i].float3Value.x, arg[i].float3Value.y, arg[i].float3Value.z); |
no test coverage detected