저는이 프로그램을 사용하는 첫 번째 프로그램이 새로 도입되었습니다. 이 코드는 루아 파일을 사용하여 내가 작업중인 게임의 메뉴를 만듭니다.Lua.GetFunction Null을 반환합니다.
이 줄은 MainMenu 화면에 단추를 만들고 단추를 누를 때 호출 할 함수의 이름을 보냅니다.
루아 :
CreateButton("mainmenu", "NewGame", "New Game", 50, 120, 150, 32)
function NewGame()
--CODE TO START NEW GAME
end
C 번호 : 버튼을 클릭하고 그것은 Funtion.Call에 null 참조 예외를 throw 관련 기능 를 호출하려고 할 때까지
public class LuaWrapper
{
public void Initialize()
{
lua = new Lua();
lua.RegisterFunction("CreateButton", this,
this.GetType().GetMethod("CreateButton"));
lua.DoFile("Data/Menus/Main.lua");
}
public void CreateButton(string window, string functionName, string text,
float posx, float posy, float width, float height)
{
ButtonControl button = new ButtonControl();
button.Bounds = new UniRectangle(posx, posy, width, height);
button.Text = text;
LuaFunction f = lua.GetFunction(functionName); // <-- RETURNS NULL ?
ButtonPressEvent pressEvent = new ButtonPressEvent(f);
button.Pressed += new EventHandler(pressEvent.button_Pressed);
WindowDictionary[window].Children.Add(button);
}
}
class ButtonPressEvent
{
LuaFunction function;
public ButtonPress(LuaFunction function)
{
this.function = function;
}
public void button_Pressed(object sender, EventArgs e)
{
function.Call();
}
}
그것은 모두가 잘 작동(); ButtonPress 클래스 아래에 있습니다. 나는 브레이크 포인트를 사용하고 문제가
LuaFunction f = lua.GetFunction(functionName);
반환 null 인 것을 발견했다.
참고 : 나는 또한 동일한 결과로
LuaFunction f = lua.GetFunction("NewGame");
시도했습니다.
감사합니다. 내가 잘못 한 것을 지적 할 수있는 사람이 있으면 좋겠습니다.
이 기능은 정의되지 않습니다. 귀하의 NewGame 코드가 정확한지 확실합니까? –
예, 고맙습니다. 게시 한 내용을 기억하고 발생했던 다른 문제를 해결했습니다. :) – Dusty