我正在尝试编写外部Lua模块.
我在Windows 8.1上工作,我使用gcc作为编译器.
我的要求是自己构建/编译所有内容,而无需使用在线提供的预编译文件.
首先,我构建了Lua 5.2.4的C源代码如下:
gcc -c*.c
ren lua.o lua.obj
ren luac.o luac.obj
ar rcs luaX.XXlib*.o
gcc -shared -o luaX.XXdll*.o
gcc lua.c luaX.XXlib -o luaX.XXexe
gcc luac.c luaX.XXlib -o luacX.XXexe
del*.o*.obj
X.X.X
源代码修订在哪里.
一旦我创建了我的.exe,我就编写了我的模块的C代码(让我们称之为LuaMath):
#include<windows.h>
#include<math.h>
#include "lauxlib.h"
#include "lua.h"
static int IdentityMatrix(lua_State *L)
{
int in = lua_gettop(L);
if (in!=1)
{
lua_pushstring(L,"Maximum 1 argument");
lua_error(L);
}
lua_Number n = lua_tonumber(L,1);
lua_newtable(L); /* tabOUT n */
int i,j;
for (i=1;i<=n;i++)
{
lua_newtable(L); /* row(i) tabOUT n */
lua_pushnumber(L,i); /* …
Run Code Online (Sandbox Code Playgroud) 这是我对这个令人难以置信的社区的第一个问题.
在这些日子里,我正在为自己写一个Lua模块.这是问题的最小部分代码
mt = {}
bf = {}
------------
-- bf.new --
------------
function bf.new(A)
local out = A
setmetatable(out,mt)
return out
end
-----------------
-- bf.tostring --
-----------------
function bf.tostring(A)
local typeA = type(A)
local out = ""
if typeA=="number" or typeA=="boolean" then
print(tostring(A))
elseif typeA=="table" then
local col = ""
local m = #A
local typeA1 = type(A[1])
for i=1,m do
if typeA1=="table" then
n = #A[1]
for j=1,n do
out = out.." "..tostring(A[i][j])
if j==n then
out = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Lua C API创建一个userdata,其中有一个metatable关联,我将收集一个矩阵.
我不能得到的是如何将初始化矩阵的每个分量设置为零.
我正如我在此描述的那样编译我的Lua模块C代码.
我的C代码如下:
#include "lauxlib.h"
#include "lua.h"
typedef struct {
LUA_NUMBER data[1][1];
int row;
int col;
}matrix;
// Create a matrix full of zeros
static int lb_newmatrix(lua_State *L)
{
// Variable declarations
int i,j;
matrix *temp;
// Input checks
if (lua_gettop(L)!=2)
{
lua_pushstring(L,"\n Two input required");
lua_error(L);
}
//--> Check I° index m riga
luaL_checktype(L,1,LUA_TNUMBER);
if (lua_tonumber(L,1)<0)
{
lua_pushstring(L,"\nRow number must be positive");
lua_error(L);
}
//--> Check II° index n colonna
luaL_checktype(L,2,LUA_TNUMBER);
if (lua_tonumber(L,2)<0)
{ …
Run Code Online (Sandbox Code Playgroud) As the title said:
Is there an Equivalent scanf function in Lua?
I mean, I want to have a syntax like this:
word_typed = lua_scanf()
Run Code Online (Sandbox Code Playgroud)
一旦我写了一个字符串(让我们说"123是完整的数字"),我就有了字符串"123 is perfect number".
提前谢谢了
PS如果需要,您可以根据需要提供LUA C API解决方案!:P