Lua枚举

AccessingEnum.cs

  1. using UnityEngine;
  2. using System;
  3. using LuaInterface;
  4. public class AccessingEnum : MonoBehaviour
  5. {
  6. string script =
  7. @"
  8. space = nil
  9. function TestEnum(e)
  10. print('Enum is:'..tostring(e))
  11. if space:ToInt() == 0 then
  12. print('enum ToInt() is ok')
  13. end
  14. if not space:Equals(0) then
  15. print('enum compare int is ok')
  16. end
  17. if space == e then
  18. print('enum compare enum is ok')
  19. end
  20. local s = UnityEngine.Space.IntToEnum(0)
  21. if space == s then
  22. print('IntToEnum change type is ok')
  23. end
  24. end
  25. function ChangeLightType(light, type)
  26. print('change light type to Directional')
  27. light.type = UnityEngine.LightType.Directional
  28. end
  29. ";
  30. void Start ()
  31. {
  32. LuaState state = new LuaState();
  33. state.Start();
  34. LuaBinder.Bind(state);
  35. state.DoString(script);
  36. state["space"] = Space.World;
  37. LuaFunction func = state.GetFunction("TestEnum");
  38. func.BeginPCall();
  39. func.Push(Space.World);
  40. func.PCall();
  41. func.EndPCall();
  42. func.Dispose();
  43. func = null;
  44. GameObject go = GameObject.Find("/Light");
  45. Light light = go.GetComponent<Light>();
  46. func = state.GetFunction("ChangeLightType");
  47. func.BeginPCall();
  48. func.Push(light);
  49. func.Push(LightType.Directional);
  50. func.PCall();
  51. func.EndPCall();
  52. func.Dispose();
  53. func = null;
  54. state.CheckTop();
  55. state.Dispose();
  56. state = null;
  57. }
  58. }

?