Fio:LuaBinder
From Fio
(→Lua Binder) |
|||
Line 9: | Line 9: | ||
* npc behavior | * npc behavior | ||
- | All the logics/policies are build on the mechanims carried out by c++ classes which will do the real work of rendering, timing, event dispatching etc. This | + | All the logics/policies are build on the mechanims carried out by c++ classes which will do the real work of rendering, timing, event dispatching etc. This seperation is to make the game fully data driven - thru scripting the logic itself is taken as data which can be easily modified without the re-compile-link of the mechanism part(or the engine). |
- | Lua has provided a bunch of API for "the host program to communicate with Lua". | + | Lua has provided a bunch of [http://www.lua.org/manual/5.1/manual.html API]s for "the host program to communicate with Lua". To call function from lua into c++, we have to: |
* extract the arguments from lua stack; | * extract the arguments from lua stack; | ||
* check the argument/return value type; | * check the argument/return value type; | ||
* call c++ function; | * call c++ function; | ||
* push the return value onto lua stack; | * push the return value onto lua stack; | ||
- | * take care the return value life time. | + | * take care the return value's life time. |
thru Lua APIs. | thru Lua APIs. | ||
- | As the number of classes need to be embedded into lua increases, these routine work will be a burden to write and maintain for each function call. There're quite a few [http://lua-users.org/wiki/LuaAddons binders] out there to make the embedding easier. In Fio we implement a home brew binder - LuaUtil. | + | As the number of classes need to be embedded into lua increases, these routine work will be a burden to write and maintain for each function call. There're quite a few [http://lua-users.org/wiki/LuaAddons binders] out there to make the embedding easier. In Fio we implement a home brew binder - LuaUtil as a bridge between c++ and lua world.(for better understanding of scripting and faster compiling speed) |
===Quick Tour=== | ===Quick Tour=== |
Revision as of 14:39, 17 September 2006
"Like a bridge over troubled water..." - Simon and Garfunkel
still in ctoring
Contents |
Lua Binder
Fio use Lua as scripting language to implement the game logic which include(in a broad sense):
- UI design and switching
- event handler
- combat scheduler
- npc behavior
All the logics/policies are build on the mechanims carried out by c++ classes which will do the real work of rendering, timing, event dispatching etc. This seperation is to make the game fully data driven - thru scripting the logic itself is taken as data which can be easily modified without the re-compile-link of the mechanism part(or the engine).
Lua has provided a bunch of APIs for "the host program to communicate with Lua". To call function from lua into c++, we have to:
- extract the arguments from lua stack;
- check the argument/return value type;
- call c++ function;
- push the return value onto lua stack;
- take care the return value's life time.
thru Lua APIs.
As the number of classes need to be embedded into lua increases, these routine work will be a burden to write and maintain for each function call. There're quite a few binders out there to make the embedding easier. In Fio we implement a home brew binder - LuaUtil as a bridge between c++ and lua world.(for better understanding of scripting and faster compiling speed)
Quick Tour
The Lua Application Program Interface
Construct An Object
- normal
- lightweight
Method Invoking
- method wrap
from lua into c++
- traits
- Overload
from c++ into lua
callback?
Type Checking
LSP
Destruct & Object Lifetime in the 2 Worlds
Misc
- const
- panic
- utility functions