usingUnityengine;usingSystem.Collections;usingLuainterface; Public classTestluacall:monobehaviour {//Use this for initialization voidStart () {luastate S=Newluastate (); if(S = =NULL)return; S.start (); S.dofile ("Test1.lua"); S.dofile ("Test2.lua"); Luafunction LF= S.getfunction ("Cdata.init"); if(LF = =NULL) {Debug.Log ("LF = = NULL------------------"); return; } luatable lb= S.gettable ("CDATA"); Lf. Beginpcall (); Lf. Push (LB); Lf. Push ("Hello"); Lf. Push (10101); Lf. Pcall (); Lf. Endpcall (); Luafunction LF2= S.getfunction ("Ctest.initdata"); if(Lf2 = =NULL) {Debug.Log ("LF2 = = NULL-------------------"); return; } } //Update is called once per frame voidUpdate () {}}
Test1.lua
CDATA ={x= About}functionfunction_name ()--BodyEndCdata.init=function(self, str, num)Print("------------------".. Str..",".. Num.."-------------------") Print(self)Print(CDATA)Print(self.x)Endcdata.update=function(self)End
C # calls LUA functions