vb 调用lua函数
Private Function f(ByVal hState As Long, ByVal x As Long) As String Dim z As String Dim hRet As Long hRet = lua_getglobal(hState, "f") hRet = lua_pushnumber(hState, x) hRet = lua_pcall(hState, 1, 1, 0) If hRet <> 0 Then Debug.Print "error lua_pcall:" & hRet z = lua_tostring(hState, -1) hRet = lua_pop(hState, 1) f = zEnd FunctionPublic Function AddFunc() Dim hState As Long, hRet As Long hState = lua_open If hState <> 0 Then hRet = luaopen_base(hState) hRet = luaL_openlibs(hState) hRet = luaopen_string(hState) hRet = luaL_dofile(hState, App.Path + "\test.lua") If hRet = 0 Then Debug.Print f(hState, 2) Else Debug.Print "luaL_dofile:" & hRet End If lua_close hState hState = 0 End IfEnd Function