1.將lua中基本資料對映到c#型別
lua中資料
c#a=1
str="小明" --檔案編碼改為utf-8
isright=true
2.將lua中的table對映到c#中的listluaint a = env.global.get("a");
string str = env.global.get("str");
bool isright = env.global.get("isright");
c#tablelist=
tablelist1=
3.將lua中的table對映到c#中的dictionary//注意lua中的資料型別
listintlist = env.global.get>("tablelist");
liststrlist = env.global.get>("tablelist1");
dic= --注意此處 key1 不能寫成 "key1"
dictionarydic = env.global.get>("dic");
4.將lua中的table對映到c#中的class或structlua
person=
c#
5.將lua中的table對映到c#中的inte***ceclass person
struct personstruct
person per = env.global.get("person");
personstruct per1 = env.global.get("person");
特別注意,對映到介面時,必須在此介面上打上[csharpcalllua]標籤!!!而且需要生成**,註冊xlua選單中的generatecode hotfix inject in editor.[csharpcalllua]//此處注意必須打上此標籤!!
inte***ce iperson
int age
}iperson per2 = env.global.get("person");
如果打上標籤後仍會報以下錯誤
可能是你的unity版本太新了。。。。,同樣的在lua方法對映到c#委託的時候也可能會遇到。
6.將lua中的table對映到c#中的luatable
6.將lua中的全域性function對映到c#中的delegatelua:luatable table = env.global.get("person");
string name = table.get("name");
int age = table.get("age");
c#中定義委託function add(num1,num2)
return num1+num2
end
特別注意,對映到委託時,必須打上[csharpcalllua]標籤!!!而且需要生成**,註冊xlua選單中的generatecode hotfix inject in editor.[csharpcalllua]
delegate int add(int num1, int num2);
add add = env.global.get("add");
debug.log(add(1, 2));
6.將lua中的全域性function對映到c#中的luafunction
建議:table對映為inte***ce,function對映為delegate。luafunction luafunc = env.global.get("add");
object res = luafunc.call(1, 2);
XLua學習 C 訪問Lua 變數,表,函式
首先通過luaenv.dostring 獲取到lua中的內容。然後通過luaenv.global.get方法可以對其中的屬性進行獲取。luaenv env new luaenv env.dostring require csharpcalllua lua檔名 1.獲取全域性變數的基本屬性型別 例 l...
XLua框架學習(三)C 訪問Lua中的全域性函式
function add print add endusing xlua luaenv luaenv newluaenv luaenv.dostring require csharpcalllua 需要先將lua指令碼載入進來 action add1 luaenv.global.get action...
Xlua基礎 三 Lua呼叫C
1.new c 物件 local newgameobj cs.unityengine.gameobject local newgameobj2 cs.unityengine.gameobject helloworld print newgameobj,newgameobj2 2.訪問靜態屬性,方法 ...