mirror of
https://github.com/lxsang/antd-lua-plugin
synced 2025-02-21 18:22:47 +01:00
fix some stuff
This commit is contained in:
parent
80f77a1f75
commit
55f298d249
@ -55,6 +55,15 @@ if lib then
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fn = FFI.lookup(lib, "buff")
|
||||||
|
if(fn) then
|
||||||
|
local ptr = FFI.call(FFI.atomic(FFI.type.POINTER),{}, fn, {})
|
||||||
|
echo(FFI.string(ptr))
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
FFI.unloadAll()
|
FFI.unloadAll()
|
||||||
end
|
end
|
||||||
echo("end the day")
|
echo("end the day")
|
@ -1,5 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
char data[] = {'h', 'e','l', 'l', 'o'};
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
char a;
|
char a;
|
||||||
@ -31,4 +32,9 @@ void test_string(char* buff, const char* a)
|
|||||||
{
|
{
|
||||||
sprintf(buff,"you say %s", a);
|
sprintf(buff,"you say %s", a);
|
||||||
printf("%s\n", buff);
|
printf("%s\n", buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
char * buff()
|
||||||
|
{
|
||||||
|
return data;
|
||||||
}
|
}
|
@ -529,6 +529,18 @@ static int l_ffi_offset(lua_State* L)
|
|||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
static int l_ffi_byte_at(lua_State* L)
|
||||||
|
{
|
||||||
|
void* ptr = lua_touserdata(L, 1);
|
||||||
|
int off = luaL_checkinteger(L,2);
|
||||||
|
if(ptr)
|
||||||
|
{
|
||||||
|
lua_pushnumber(L, *((uint8_t*)(ptr + off)));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
static int l_ffi_string(lua_State* L)
|
static int l_ffi_string(lua_State* L)
|
||||||
{
|
{
|
||||||
void* ptr = lua_touserdata(L,1);
|
void* ptr = lua_touserdata(L,1);
|
||||||
@ -546,6 +558,16 @@ static int l_ffi_free(lua_State* L)
|
|||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
static int l_ffi_bytearray(lua_State* L)
|
||||||
|
{
|
||||||
|
void* ptr = lua_touserdata(L,1);
|
||||||
|
int size = luaL_checknumber(L,2);
|
||||||
|
//create new bytearray
|
||||||
|
lua_new_byte_array(L,size);
|
||||||
|
byte_array_t *ba = l_check_barray(L,-1);
|
||||||
|
memcpy(ba->data, ptr, size);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
static const struct luaL_Reg _lib [] = {
|
static const struct luaL_Reg _lib [] = {
|
||||||
{"dlopen", l_dlopen},
|
{"dlopen", l_dlopen},
|
||||||
{"dlsym",l_dlsym},
|
{"dlsym",l_dlsym},
|
||||||
@ -556,8 +578,11 @@ static const struct luaL_Reg _lib [] = {
|
|||||||
{"new", l_ffi_new},
|
{"new", l_ffi_new},
|
||||||
{"meta", l_ffi_meta},
|
{"meta", l_ffi_meta},
|
||||||
{"at", l_ffi_offset},
|
{"at", l_ffi_offset},
|
||||||
|
{"byteAt", l_ffi_byte_at},
|
||||||
// special case: pointer to string
|
// special case: pointer to string
|
||||||
{"string", l_ffi_string},
|
{"string", l_ffi_string},
|
||||||
|
// pointer to byte array
|
||||||
|
{"bytearray", l_ffi_bytearray},
|
||||||
{"free", l_ffi_free},
|
{"free", l_ffi_free},
|
||||||
{NULL,NULL}
|
{NULL,NULL}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user