|
36 | 36 | --> |
37 | 37 |
|
38 | 38 | # XS in C |
39 | | -Revised: July 2, 2025 |
| 39 | +Revised: October 2, 2025 |
40 | 40 |
|
41 | 41 | **See end of document for [copyright and license](#license)** |
42 | 42 |
|
@@ -797,6 +797,10 @@ This section describes the macros related to accessing properties of objects (or |
797 | 797 | <td><code>xsCall0</code> ... <code>xsCall7, xsmcCall</code></td> |
798 | 798 | <td>Calls the function referred to by a property of an instance</td> |
799 | 799 | </tr> |
| 800 | + <tr> |
| 801 | + <td><code>xsCallFunction0</code> ... <code> xsCallFunction8</code></td> |
| 802 | + <td>Calls the function with the provided instance as <code>this</code></td> |
| 803 | + </tr> |
800 | 804 | <tr> |
801 | 805 | <td><code>xsNew0</code> ... <code>xsNew7, xsmcNew</code></td> |
802 | 806 | <td>Calls the constructor referred to by a property of an instance</td> |
@@ -1344,7 +1348,7 @@ this[0](2, 3) |
1344 | 1348 |
|
1345 | 1349 | ##### In C: |
1346 | 1350 |
|
1347 | | -``` |
| 1351 | +```c |
1348 | 1352 | xsCall0(xsGlobal, xsID_foo); |
1349 | 1353 | xsCall1(xsThis, xsID("foo"), xsInteger(1)); |
1350 | 1354 | xsCall2(xsThis, 0, xsInteger(2), xsInteger(3)); |
@@ -1385,6 +1389,43 @@ xsmcCall(xsResult, xsThis, 0, &xsVar(1), &xsVar(2), NULL); |
1385 | 1389 |
|
1386 | 1390 | *** |
1387 | 1391 |
|
| 1392 | +#### xsCallFunction* |
| 1393 | +
|
| 1394 | +When you have a reference to a function, you can call the function with one of the `xsCallFunction*` macros (where `*` is `0` through `7`, representing the number of parameter slots passed). If the value is not a reference to a function, the `xsCall*` macro throws an exception. |
| 1395 | +
|
| 1396 | +**`xsSlot xsCallFunction0(xsSlot theFunction, xsSlot theThis)`**<BR> |
| 1397 | +**`xsSlot xsCallFunction1(xsSlot theFunction, xsSlot theThis, xsSlot theParam0)`**<BR> |
| 1398 | +**`xsSlot xsCallFunction2(xsSlot theFunction, xsSlot theThis, xsSlot theParam0, xsSlot theParam1)`**<BR> |
| 1399 | +**`xsSlot xsCallFunction3(xsSlot theFunction, xsSlot theThis, xsSlot theParam0, xsSlot theParam1, xsSlot theParam2)`**<BR> |
| 1400 | +**`xsSlot xsCallFunction4(xsSlot theFunction, xsSlot theThis, xsSlot theParam0, xsSlot theParam1, xsSlot theParam2, xsSlot theParam3)`**<BR> |
| 1401 | +**`xsSlot xsCallFunction5(xsSlot theFunction, xsSlot theThis, xsSlot theParam0, xsSlot theParam1, xsSlot theParam2, xsSlot theParam3, xsSlot theParam4)`**<BR> |
| 1402 | +**`xsSlot xsCallFunction6(xsSlot theFunction, xsSlot theThis, xsSlot theParam0, xsSlot theParam1, xsSlot theParam2, xsSlot theParam3, xsSlot theParam4, xsSlot theParam5)`**<BR> |
| 1403 | +**`xsSlot xsCallFunction7(xsSlot theFunction, xsSlot theThis, xsSlot theParam0, xsSlot theParam1, xsSlot theParam2, xsSlot theParam3, xsSlot theParam4, xsSlot theParam5, xsSlot theParam6)`** |
| 1404 | +
|
| 1405 | +| Arguments | Description | |
| 1406 | +| --- | :-- | |
| 1407 | +| `theFunction` | A reference to a function instance |
| 1408 | +| `theThis` | A reference to the instance that will be `this` when the function is called |
| 1409 | +| `theParam0` ... `theParam6` | The parameter slots to pass to the function |
| 1410 | +
|
| 1411 | +Returns the result slot of the function |
| 1412 | +
|
| 1413 | +##### In ECMAScript: |
| 1414 | +
|
| 1415 | +```javascript |
| 1416 | +foo.call() |
| 1417 | +foo.call(device, 12); |
| 1418 | +``` |
| 1419 | + |
| 1420 | +##### In C: |
| 1421 | + |
| 1422 | +```c |
| 1423 | +xsCallFunction0(xsGet(xsGlobal, xsID_foo), xsGlobal); |
| 1424 | +xsCallFunction1(xsThis, xsID("foo"), xsGet(xsGlobal, xsID("device"), xsInteger(12)); |
| 1425 | +``` |
| 1426 | +
|
| 1427 | +*** |
| 1428 | +
|
1388 | 1429 | <a id="xsnew"></a> |
1389 | 1430 | #### xsNew* |
1390 | 1431 |
|
@@ -1841,7 +1882,7 @@ XS in C defines the following macros to throw specific exceptions. |
1841 | 1882 |
|
1842 | 1883 | ##### In C: |
1843 | 1884 |
|
1844 | | -``` |
| 1885 | +```c |
1845 | 1886 | xpt2046 xpt = calloc(1, sizeof(xpt2046Record)); |
1846 | 1887 | if (!xpt) xsUnknownError("out of memory"); |
1847 | 1888 |
|
|
0 commit comments