TestString.cs

  1. using UnityEngine;
  2. using System.Collections;
  3. using LuaInterface;
  4. using System;
  5. using System.Reflection;
  6. using System.Text;
  7. public class TestString : LuaClient
  8. {
  9. string script =
  10. @"
  11. function Test()
  12. local str = System.String.New('男儿当自强')
  13. local index = str:IndexOfAny('儿自')
  14. print('and index is: '..index)
  15. local buffer = str:ToCharArray()
  16. print('str type is: '..type(str)..' buffer[0] is ' .. buffer[0])
  17. local luastr = tolua.tolstring(buffer)
  18. print('lua string is: '..luastr..' type is: '..type(luastr))
  19. luastr = tolua.tolstring(str)
  20. print('lua string is: '..luastr)
  21. end
  22. ";
  23. protected override LuaFileUtils InitLoader()
  24. {
  25. return new LuaResLoader();
  26. }
  27. //屏蔽,例子不需要运行
  28. protected override void CallMain() { }
  29. protected override void OnLoadFinished()
  30. {
  31. base.OnLoadFinished();
  32. luaState.DoString(script);
  33. LuaFunction func = luaState.GetFunction("Test");
  34. func.Call();
  35. func.Dispose();
  36. func = null;
  37. }
  38. }

?