Lua PANIC error
Lua PANIC error
我正在用c++创建一个数独求解器,同时实现用于实际解决谜题的Lua脚本。我已经创建了以下Lua代码,但得到一个
当我的c++代码到达lua_call的第一个实例时,PANIC:调用Lua API时未受保护的错误(尝试调用nil值)
错误。在SciTE中编译代码时,我得到以下错误:
lua: SudokuSolver。Lua:99: 'end'预期(在第61行关闭'for')附近的"
在第61行有for循环的函数末尾添加三个'end'可以清除该错误,但会在c++程序中导致错误。有人可以看看我的Lua,看看是否有任何语法错误或其他问题,可能会导致这一点?谢谢你
代码-- Table Declaration
SudokuGrid = {}
function RecieveGrid ( _Pos, _Value )
-- Recives the cell value at _Pos position from C++
SudokuGrid[_Pos] = _Value
end
function SolveSudoku ( _Pos )
-- Recursive function which solves the sudoku puzzle
local iNewValue = 1
-- If Position is 82+, all cells are solved
if( _Pos >= 82 ) then
return true
end
-- If Position already has a value
if( SudokuGrid[_Pos] ~= 0) then
return SolveSudoku( _Pos + 1 )
else
while(true) do
SudokuGrid[_Pos] = iNewValue
iNewValue = iNewValue + 1
-- If the new value of the cell is higher than 9 its not valid
if( SudokuGrid[_Pos] > 9 ) then
--Reset value
SudokuGrid[_Pos] = 0
return false
end
if( IsValid( _Pos ) and SolveSudoku( _Pos + 1 ) ) then
return true
end
end
end
end
function IsValid ( _Pos )
-- Calculate Column and Row in Grid
x = _Pos % 9
if( x == 0 ) then
x = 9
end
y = math.ceil(_Pos / 9)
-- Check Rows
for i=1, 9 do
CheckVal = ((y - 1) * 9) + i
if( CheckVal == _Pos ) then
-- Do nothing
else if ( SudokuGrid[_Pos] == SudokuGrid[CheckVal]and SudokuGrid[_Pos] ~= 0 ) then
return false
else
-- Do nothing
end
end
-- Check Columns
for i=1, 9 do
CheckVal = ((i - 1) * 9) + x
if( CheckVal == _Pos ) then
-- Do nothing
else if ( SudokuGrid[_Pos] == SudokuGrid[CheckVal] and SudokuGrid[_Pos] ~= 0 ) then
return false
else
-- Do nothing
end
end
-- Check 3X3 Grid
SquareCol = math.ceil(x/3)
SquareRow = math.ceil(y/3)
StartVal = (SquareCol - 1) * 27 + (SquareRow * 3) -2
for j=0, 2 do
for i=0, 2 do
CheckVal = StartVal + i
if( CheckVal == _Pos ) then
-- Do nothing
else if ( SudokuGrid[_Pos] == SudokuGrid[CheckVal] and SudokuGrid[_Pos] ~= 0 ) then
return false
else
-- Do nothing
end
end
StartVal = StartVal + 9
end
return true
end
function SendGrid ( _Pos )
-- Sends the value at _Pos to C++
return SudokuGrid[_Pos]
end
包含else if
:
else if ( SudokuGrid[_Pos] == SudokuGrid[CheckVal]and SudokuGrid[_Pos] ~= 0 ) then
在Lua中,使用elseif
代替。使用else if
需要更多的关闭end
。
elseif SudokuGrid[_Pos] == SudokuGrid[CheckVal] and SudokuGrid[_Pos] ~= 0 then
相关文章:
- "error: no matching function for call to"构造函数错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- C++错误:"error: int aaa::bbb is protected within this context"
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- C++ "error: invalid use of void expression"
- struct.error:解压缩 C++ 结构时,解包需要 288 字节的缓冲区
- 如何修复"error: ‘_1’ was not declared in this scope"?
- 从不同目录执行时"symbol lookup error:",否则从构建目录执行时按预期工作
- 对象声明中的模板"error: expected expression"
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- OpenCV 3.4.1 error readNetFromTensorflow 无法在 cv::d nn::ReadProtoFromBinaryFile 中打开 .pb
- 已解决 - C++ 的崇高文本中的"fatal error: opencv: no such file or directory"
- 为什么我会"error: expected expression"?
- CMake Error at modules/videoio/cmake/detect_ffmpeg.cmake:16
- 如果两个静态库使用相同的另一个静态库,如何避免"LNK2005 Already Defined error"?
- Lua PANIC error