{"id":542,"date":"2019-03-10T20:23:03","date_gmt":"2019-03-10T18:23:03","guid":{"rendered":"http:\/\/www.noxis-studio.com\/blog\/?page_id=542"},"modified":"2019-03-12T01:05:07","modified_gmt":"2019-03-11T23:05:07","slug":"n3dse-script-engine","status":"publish","type":"page","link":"http:\/\/www.noxis-studio.com\/blog\/n3dse-script-engine\/","title":{"rendered":"N3DSE script engine"},"content":{"rendered":"<p>[vc_row][vc_column][vc_column_text]<\/p>\n<h3>N3DSE Script Engine<\/h3>\n<p>N3DSE is a dynamic linked library made up of a compiler and a virtual machine. Programming in N3D Script (N3DS) should not be too difficult for C++ programmers as this is similar to programming in C++ using only static classes.<\/p>\n<p>Here are some properties of N3DSE:<\/p>\n<ul>\n<li>N3DSE can compile a set of script files interacting each other.<\/li>\n<li>Each Script file is like a static class with its attributes and its methods.<\/li>\n<li>A script method can be called from C++ code or from anoter script.<\/li>\n<li>There is a base script, the System script, which methods are hard C++ coded functions. The user can add them to the system using pointer to functions.<\/li>\n<\/ul>\n<p>The following diagram sums up the way N3DSE works.[\/vc_column_text][vc_single_image image=&#8221;544&#8243; img_size=&#8221;large&#8221; alignment=&#8221;center&#8221;][vc_column_text]<\/p>\n<h3>Creating a script<\/h3>\n<p>A script is associated with a file. This means that there can only be one script per file (like in java). A script is like a static class in C++. Each script has its name and each name must be unique. The script name \u201cSystem\u201d is reserved.<\/p>\n<p>Here is the syntax to write a script :<\/p>\n<div style=\"border: 1px solid black;\">\n<pre><span style=\"color: #0000ff;\">script <\/span>script_name\n{\n    #code of the script#\n}\n<\/pre>\n<\/div>\n<p>NB: comments are inside \u201cdiesis brackets\u201d<\/p>\n<h3>Declaring variables<\/h3>\n<p>There are 4 primitive types in N3DS. They are exactly the same as the associated C types<\/p>\n<ul>\n<li>Double<\/li>\n<li>Integer<\/li>\n<li>Bool<\/li>\n<li>Char<\/li>\n<\/ul>\n<p>N3DS also enables the use of arrays of these primitive types.<\/p>\n<p>Variable declarations and initializations are done using the keyword <b>declare<\/b>:<\/p>\n<div style=\"border: 1px solid black;\">\n<pre><span style=\"color: #0000ff;\"> declare bool <\/span> condition = false;\n<span style=\"color: #0000ff;\"> declare double <\/span> variable;\n<span style=\"color: #0000ff;\"> declare int <\/span> array = <span style=\"color: #0000ff;\">new<\/span> [10];\n<\/pre>\n<\/div>\n<p>NB: simple variables needn\u2019t to be initialized while arrays must be initialized with there size.<\/p>\n<h3 class=\"western\" lang=\"fr-FR\">Operations on expressions and assignments<\/h3>\n<p>The operations on expressions are similar to C\/C++ operations (+, &#8211; , *, \/)<\/p>\n<p>NB: strings (arrays of chars) can be concatenated with any other expression using the<\/p>\n<p>+ operator.<\/p>\n<p>Assignments are made using the keyword <b>set<\/b>:<\/p>\n<div style=\"border: 1px solid black;\">\n<pre><span style=\"color: #0000ff;\">set<\/span> myVar = 2*array[2];\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h3>Declaring functions<\/h3>\n<p>Functions are declared exactly like in C programming.<\/p>\n<p>Ex:<\/p>\n<div style=\"border: 1px solid black;\">\n<pre><span style=\"color: #0000ff;\">int<\/span> inc(<span style=\"color: #0000ff;\">int<\/span> var1)\n{\n    <span style=\"color: #0000ff;\">return<\/span> var1 + 1;\n}\n<\/pre>\n<\/div>\n<p>N3DS also enables the use of references thanks to the keyword <b>ref<\/b><\/p>\n<p>Ex:<\/p>\n<div style=\"border: 1px solid black;\">\n<pre><span style=\"color: #0000ff;\">void<\/span> inc(<span style=\"color: #0000ff;\">ref<\/span> <span style=\"color: #0000ff;\">int<\/span> var1)\n{\n    <span style=\"color: #0000ff;\">set<\/span> var1 = var1 + 1;\n}\n<\/pre>\n<\/div>\n<h3 class=\"western\">Calling functions<\/h3>\n<p>Function calls are made using the keyword <b>call.<\/b><\/p>\n<p>In any case you must specify the name of the script in which the function was declared<\/p>\n<div style=\"border: 1px solid black;\">\n<pre><span style=\"color: #0000ff;\">set<\/span> myVar = 5* <span style=\"color: #0000ff;\">call<\/span> script_name.Func_name(param1);\n<\/pre>\n<\/div>\n<p>If the reference on a variable is required, you must use the keyword <b>ref<\/b><\/p>\n<p><span style=\"color: #0000ff;\">call<\/span> script_name.Func_name2(ref param1);<br \/>\nNB: Every function of any script can be called by the user. The dll provides methods to set the arguments of the function and then to call it.<\/p>\n<h3 class=\"western\">System\/Extern functions<\/h3>\n<p>System\/extern functions are hard coded C++ functions which can be called from the script.<\/p>\n<p>This enables the user to extend the language with functions coded and compiled with a C++ compiler. He can then enjoy speed and access extern data.<\/p>\n<p>In order to access extern functions, you must first write their prototypes in one of the script files.<\/p>\n<p>In order to write the prototype of an extern function, you must use the keyword <b>prototype<\/b>:<\/p>\n<div style=\"border: 1px solid black;\">\n<pre><span style=\"color: #0000ff;\">prototype<\/span> <span style=\"color: #0000ff;\">int<\/span> func_name(<span style=\"color: #0000ff;\">int<\/span> param1);\n<\/pre>\n<\/div>\n<p>When you call a system function, you must consider that they belong to the <b>System script<\/b>.<\/p>\n<p>The system script is a virtual script in which all the extern functions will be stored.<\/p>\n<p>Consequently, the call of an extern function will looks like something like this:<\/p>\n<div style=\"border: 1px solid black;\">\n<pre><span style=\"color: #0000ff;\">call<\/span> System.func_name(5);\n<\/pre>\n<\/div>\n<p>If you\u2019ve declare system\/extern functions in one of your script files, you must match their prototypes with your C++ functions. A dll method is provided for that task.<\/p>\n<p>The principle is quiet simple. When you call an extern function from the script, the virtual machine will call the appropriate C++ function using its pointer to function.<\/p>\n<p>The N3DSE dll provides a set of methods in order to get the parameters and set the return value.<\/p>\n<h3 class=\"western\">If statement<\/h3>\n<p>Here is the syntax of the <i>if statement<\/i>:<\/p>\n<div style=\"border: 1px solid black;\">\n<pre><span style=\"color: #0000ff;\"> if <\/span>(condition)\n{\n    <span style=\"color: #008000;\">#body#<\/span>\n}\n<span style=\"color: #0000ff;\">else<\/span>\n{\n    <span style=\"color: #008000;\"> #else body# <\/span>\n}\n<\/pre>\n<\/div>\n<p><span style=\"font-size: small;\"> <span style=\"font-family: Verdana, sans-serif;\"> The body of an <i>if statement<\/i> is executed if the value of the condition is true.If it\u2019s false, the body of the <i> else statement <\/i> is executed. <\/span> <\/span><\/p>\n<p><span style=\"font-family: Verdana, sans-serif;\"> <span style=\"font-size: small;\"> NB: the condition must be a Boolean expression <\/span> <\/span><\/p>\n<p><span style=\"font-family: Verdana, sans-serif;\"> <span style=\"font-size: small;\"> The else statement is optional. <\/span> <\/span><\/p>\n<h3 class=\"western\">While statement<\/h3>\n<p>Here is the syntax of the <i>while statement<\/i>:<\/p>\n<div style=\"border: 1px solid black;\">\n<pre><span style=\"color: #0000ff;\"> while <\/span>(condition)\n{\n    <span style=\"color: #008000;\">#body#<\/span>\n}\n<\/pre>\n<\/div>\n<p><span style=\"font-size: small;\"> <span style=\"font-family: Verdana, sans-serif;\"> The body of a while statement is executed until the value of the condition becomes false. <\/span> <\/span><\/p>\n<p><span style=\"font-size: small;\"> <span style=\"font-family: Verdana, sans-serif;\"> NB: the condition must be a Boolean expression <\/span> <\/span>[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[vc_row][vc_column][vc_column_text] N3DSE Script Engine N3DSE is a dynamic linked library made up of a compiler and a virtual machine. Programming in N3D Script (N3DS) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"class_list":["post-542","page","type-page","status-publish","hentry"],"acf":{"full_width":false,"header_transparent":false},"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.noxis-studio.com\/blog\/wp-json\/wp\/v2\/pages\/542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.noxis-studio.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.noxis-studio.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.noxis-studio.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.noxis-studio.com\/blog\/wp-json\/wp\/v2\/comments?post=542"}],"version-history":[{"count":2,"href":"http:\/\/www.noxis-studio.com\/blog\/wp-json\/wp\/v2\/pages\/542\/revisions"}],"predecessor-version":[{"id":545,"href":"http:\/\/www.noxis-studio.com\/blog\/wp-json\/wp\/v2\/pages\/542\/revisions\/545"}],"wp:attachment":[{"href":"http:\/\/www.noxis-studio.com\/blog\/wp-json\/wp\/v2\/media?parent=542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}