2 single: C/C++ プログラムへ Ring を組み込むには; はじめに
4 ======================================
5 C/C++ プログラムへ Ring を組み込むには
6 ======================================
8 この関数により C/C++ プログラムから Ring を使えます。
12 RingState *ring_state_init();
13 ring_state_runcode(RingState *pState,const char *cCode);
14 ring_state_delete(RingState *pState);
17 pair: C/C++ プログラムへ Ring を組み込むには; Ring のステート
22 考えかたとしては ring_state_init() で Ring ステートの新規作成後に、
23 ring_state_runcode() 関数を呼び出すことで、同一ステートの Ring コードの実行します。
24 処理完了後に ring_state_delete() を呼び出して、メモリを解放します。
32 int main(int argc, char *argv[])
34 RingState *pState = ring_state_init();
36 ring_state_runcode(pState,"see 'hello world from the ring programming language'+nl");
37 ring_state_delete(pState);
45 hello world from the ring programming language
48 pair: C/C++ プログラムへ Ring を組み込むには; Ring ステート関数
53 Ring の API にはステートの作成と削除を行う関数です。
54 また、新しい変数の作成と変数の値を取得するための関数もあります。
58 RingState * ring_state_init ( void ) ;
59 RingState * ring_state_delete ( RingState *pRingState ) ;
60 void ring_state_runcode ( RingState *pRingState,const char *cStr ) ;
61 List * ring_state_findvar ( RingState *pRingState,const char *cStr ) ;
62 List * ring_state_newvar ( RingState *pRingState,const char *cStr ) ;
63 void ring_state_main ( int argc, char *argv[] ) ;
64 void ring_state_runfile ( RingState *pRingState,const char *cFileName ) ;
65 void ring_state_runobjectfile ( RingState *pRingState,const char *cFileName ) ;
68 pair: C/C++ プログラムへ Ring を組み込むには; Ring ステート変数
73 同一プログラム内で複数の Ring のステートを作成できます。また、変数の作成と値の変更もできます。
75 ring_state_findvar() 関数は変数のリストを取得します。
77 ring_state_newvar() 関数は新しい変数を作成します。
86 int main(int argc, char *argv[])
90 RingState *pState = ring_state_init();
91 RingState *pState2 = ring_state_init();
94 ring_state_runcode(pState,"see 'hello world from the ring programming language'+nl");
96 printf("Again from C we will call ring code\n");
97 ring_state_runcode(pState,"for x = 1 to 10 see x + nl next");
99 ring_state_runcode(pState2,"for x = 1 to 5 see x + nl next");
101 printf("Now we will display the x variable value from ring code\n");
102 ring_state_runcode(pState,"see 'x value : ' + x + nl ");
103 ring_state_runcode(pState2,"see 'x value : ' + x + nl ");
105 pList = ring_state_findvar(pState,"x");
107 printf("Printing Ring variable value from C , %.0f\n",
108 ring_list_getdouble(pList,RING_VAR_VALUE));
110 printf("now we will set the ring variable value from C\n");
111 ring_list_setdouble(pList,RING_VAR_VALUE,20);
113 ring_state_runcode(pState,"see 'x value after update : ' + x + nl ");
115 pList = ring_state_newvar(pState,"v1");
116 ring_list_setdouble(pList,RING_VAR_VALUE,10);
118 pList = ring_state_newvar(pState,"v2");
119 ring_list_setdouble(pList,RING_VAR_VALUE,20);
121 ring_state_runcode(pState,"see 'v1 + v2 = ' see v1+v2 see nl");
123 ring_state_runcode(pState,"see 'end of test' + nl");
125 ring_state_delete(pState);
126 ring_state_delete(pState2);
134 hello world from the ring programming language
135 Again from C we will call ring code
151 Now we will display the x variable value from ring code
154 Printing Ring variable value from C , 11
155 now we will set the ring variable value from C
156 x value after update : 20