Embedded Lua Demo |
|
happosai
高階會員 發表:93 回覆:228 積分:109 註冊:2002-09-15 發送簡訊給我 |
前言
====
在下曾經在"通訊協定設計經驗談"一文中提到過 Lua,Lua 是一個非常精簡的 script,
與我們熟知的其他 script 有一點不同的是,Lua 被創造出來的目的是為了能夠嵌入、
擴充一般的應用程式。GAME 可能是 Lua 最廣為人知的應用,例如博德之門、萬艦齊發等
都使用了 Lua 作為 script engine,玩家可以藉由 script 創作新物件、新任務、甚至
是一個完全不同的世界,徹底改變了大多數人對遊戲的看法。 示範
====
Lua 的最大缺點就是缺少良好的說明文件,直到最近才出了一本書,不像
對手 Python 書籍多如牛毛,Lua 官方網站的資料對初學者來說很難下嚥,
還好 Lua 的愛好者建立了一個交流網站: http://lua-users.org/ 這邊有三篇教學,更適合初學者
http://tonyandpaige.com/tutorials/ 小弟花了幾天的時間消化吸收上面的範例,寫了一個簡單的 demo,
主要包括了:
* 如何重導錯誤訊息
* 如何註冊 C function 到 Lua
* 如何檢查參數是否合法
* 如何傳遞一個 table 至 C function(table類似Perl的關連式陣列)
* 如何自訂結構(C struct)
* 如何從記憶體執行 script 請至下列網址下載:
http://akk.fengsoft.com/Lua5.rar 註:需使用 BCB6(Patch4) 編譯 當然,Lua 可不止這些,希望藉由小弟的拋磚引玉,吸引更多高手
一起研究、一起分享這個有趣的語言......:) Python 與 Lua 的比較
==================== http://lua-users.org/wiki/LuaVersusPython 出自 Lua
陣營,當然不可能100%公正,不過小弟有興趣的是 multithreading
這方面,Python 無法產生多個各自獨立的 interpreter 以
multithreading 並行執行這件事恐怕是真的。 雖然 Python 有一個 C API - Py_NewInterpreter();但是實際以 multithreading
方式執行時仍然要使用一個 global interpreter lock,也就是說雖然可以產生
各自獨立的 interpreter,但是同時只能有一個 interpreter 可以執行,Python
官方釋出的 sample code 可以證明了這一點,這個 sample code 在下面的目錄可以找到 [Python Source]\Demo\pysvr\pysvr.c 註:曾經有一位老遊戲設計師告訴筆者,在 win32 的環境 multi-process 的效能
優於 multithreading,有哪位朋友做過相關測試嗎? 發表人 - happosai 於 2004/01/13 10:19:57
|
happosai
高階會員 發表:93 回覆:228 積分:109 註冊:2002-09-15 發送簡訊給我 |
|
bugmans
高階會員 發表:95 回覆:322 積分:188 註冊:2003-04-12 發送簡訊給我 |
http://delphi.ktop.com.tw/board.php?cid=31&fid=79&tid=59104#29
FreePops有使用lua,我曾嘗試在bcb加入FreePops程式碼來達到收信的功能 雖然還沒有任何頭緒,但至少我能在bcb中呼叫lua的功能了 剛好這篇的檔案也無法下載了,我參考這裡的範例將bcb的lua專案檔放上來 http://gamedevgeek.com/tutorials/ Lua TutorialsGetting Started With Lua - This tutorial is a gentle introduction to the Lua scripting language. It shows the basics of integrating Lua into a C program on Linux and Windows. A simple “Hello, World!” example is provided for download.Calling Lua Functions - Building on the first tutorial, this one explains how to define functions in Lua and call them from a C program. Another simple example is provided for Windows and Linux. Calling C Functions from Lua - The conclusion of my Lua tutorials for now, this one explains how to call a C function from Lua. There is also a brief discussion of error handling. The sample program demonstrates taking a variable number of arguments and returning more than one value. bcb專案檔下載位置http://delphi.ktop.com.tw/download.php?download=upload/487f3b1270b95_lua.rar 搜尋關鍵字:lua_State,lua_open,luaL_openlibs,luaL_dofile,lua_call,lua_close
編輯記錄
bugmans 重新編輯於 2008-07-17 20:49:24, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |