| 1 |
#include "Daodan_BSL.h" |
| 2 |
#include "BFW_ScriptingLanguage.h" |
| 3 |
|
| 4 |
uint16_t ONICALL bsl_int32mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 5 |
{ |
| 6 |
if (numargs < 2) |
| 7 |
return 1; |
| 8 |
ret->value_int32 = args[0].value_int32 * args[1].value_int32; |
| 9 |
ret->type = sl_int32; |
| 10 |
return 0; |
| 11 |
} |
| 12 |
|
| 13 |
uint16_t ONICALL bsl_mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 14 |
{ |
| 15 |
if (numargs < 2) |
| 16 |
return 1; |
| 17 |
|
| 18 |
double val1; |
| 19 |
double val2; |
| 20 |
|
| 21 |
if (args[0].type == sl_int32) |
| 22 |
val1 = args[0].value_int32; |
| 23 |
else |
| 24 |
val1 = args[0].value_float; |
| 25 |
|
| 26 |
if (args[1].type == sl_int32) |
| 27 |
val2 = args[1].value_int32; |
| 28 |
else |
| 29 |
val2 = args[1].value_float; |
| 30 |
|
| 31 |
ret->value_float = (float)(val1 * val2); |
| 32 |
ret->type = sl_float; |
| 33 |
return 0; |
| 34 |
} |
| 35 |
|
| 36 |
uint16_t ONICALL bsl_int32div(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 37 |
{ |
| 38 |
if (numargs < 2) |
| 39 |
return 1; |
| 40 |
ret->value_int32 = args[0].value_int32 / args[1].value_int32; |
| 41 |
ret->type = sl_int32; |
| 42 |
return 0; |
| 43 |
} |
| 44 |
|
| 45 |
uint16_t ONICALL bsl_div(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 46 |
{ |
| 47 |
if (numargs < 2) |
| 48 |
return 1; |
| 49 |
|
| 50 |
double val1; |
| 51 |
double val2; |
| 52 |
|
| 53 |
if (args[0].type == sl_int32) |
| 54 |
val1 = args[0].value_int32; |
| 55 |
else |
| 56 |
val1 = args[0].value_float; |
| 57 |
|
| 58 |
if (args[1].type == sl_int32) |
| 59 |
val2 = args[1].value_int32; |
| 60 |
else |
| 61 |
val2 = args[1].value_float; |
| 62 |
|
| 63 |
ret->value_float = (float)(val1 / val2); |
| 64 |
ret->type = sl_float; |
| 65 |
return 0; |
| 66 |
} |
| 67 |
|
| 68 |
void SLrDaodan_Initalize() |
| 69 |
{ |
| 70 |
SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul); |
| 71 |
SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul); |
| 72 |
|
| 73 |
SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div); |
| 74 |
SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div); |
| 75 |
} |