In the following (from https://nim-lang.org/docs/backends.html), what is the point of using "{.importc.}"
Apparently it can be omitted : The example hereunder works even without it:
<html><body>
<script type="text/javascript">
function addTwoIntegers(a, b)
{
return a + b;
}
</script>
<script type="text/javascript" src="calculator.js"></script>
</body></html>
addTwoIntegers(a, b: int): int {.importc.}
when isMainModule:
echo addTwoIntegers(3, 7)
nim js -o:calculator.js calculator.nim
Sorry, wrong example here is the correct one:
Nim:
#TestNimDOM
import dom
proc main() =
var root = getElementById ("root")
var d1 = document.createElement("div")
d1.innerHTML = "This is a div"
root.appendChild(d1)
main()
HTML /JS:
<!DOCTYPE html>
<meta charset="UTF-8">
<html>
<body>
<h2>Test 1</h2>
<div id ="root"></div>
<script src="TestNimDOM.js"></script>
</body>
</html>
What is the point of an {.importc.}
Importing and using js fetch with importc example.
What is the point of an {.exportc.}
Calling the callback which defined with exportc pragma in appjs.nim example.
In your 2nd example, you didn't need any of those case, importing and/or exporting, just got away with the provided procs from library.
Remove the exportc and importc in my example and see if you can get away without those pragma.