Đang chuẩn bị liên kết để tải về tài liệu:
Programming Linux Games phần 7
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
e ( GPL ) Sau đó tất cả những người tình nguyện đã họp nhau thành từng nhóm và viết thêm những chương trình dựa trên GPL tạo nên những màu sắc của Linux. Chúng ta không thể không nhắc đến những người đã phát triển Linux này. | GAME SCRIPTING UNDER LINUX 247 Let s see exactly how this is done. Code Listing 6 2 tclshell.c A simple but functional Tcl shell. include stdio.h include stdlib.h include tcl.h int main Tcl_Interp interp char input 16384 Create an interpreter structure. interp Tcl_CreateInterp if interp NULL printf Unable to create interpreter. n return 1 Add custom commands here. Loop indefinitely we ll break on end-of-file . for int result char message Print a prompt and make it appear immediately. printf fflush stdout Read up to 16k of input. if fgets input 16383 stdin NULL printf End of input. n break Evaluate the input as a script. result Tcl_Eval interp input 248 CHAPTER 6 Print the return code and the result. switch result case TCL_OK message OK break case TCL_ERROR message ERR break case TCL_CONTINUE message CONT break default message break printf s s n message Tcl_GetStringResult interp Delete the interpreter. Tcl_DeleteInterp interp return 0 This program implements a very simple command-line Tcl shell. It collects input from standard input up to 16K of it evaluates it with Tcl_Eval and prints the result along with any errors that occurred. To compile this Tcl shell you ll need the Tcl library and the floating-point math library gcc -W -Wall -pedantic tclshell.c -o tclshell -ltcl -lm Your Tcl library may be named differently if it refuses to link with -ltcl try -ltcl8.2 or -ltcl8.3. Failing these look for something starting with libtcl in usr lib or usr local lib and use that name. This is the kind of situation in which Autoconf would be handy more on this in Chapter 10. GAME SCRIPTING UNDER LINUX 249 Go ahead and give this program a try. Feed it some of the scripts from earlier in the chapter or anything else you can think of. Remember that this simple shell can t handle partial statements for instance you can t enter proc foo g on one line and expect to continue it on the next. You can exit with an end-of-file character Ctrl-D or with the built-in exit command. Structure