mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-28 00:39:30 +00:00
Added CIA, bugfixes, portlibs update
This commit is contained in:
parent
2725dce383
commit
b19ec95cc7
14 changed files with 757 additions and 158 deletions
13
source/ctr.c
13
source/ctr.c
|
|
@ -10,6 +10,7 @@ The `ctr` module.
|
|||
#include <3ds/services/apt.h>
|
||||
#include <3ds/os.h>
|
||||
#include <3ds/svc.h>
|
||||
#include <3ds/services/hb.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
|
|
@ -252,6 +253,18 @@ int luaopen_ctr_lib(lua_State *L) {
|
|||
#endif
|
||||
lua_pushstring(L, buff);
|
||||
lua_setfield(L, -2, "root");
|
||||
|
||||
/***
|
||||
Whether or not ctrµLua has been launched with ninjhax
|
||||
@field hb
|
||||
*/
|
||||
if (!hbInit()) {
|
||||
hbExit();
|
||||
lua_pushboolean(L, true);
|
||||
} else {
|
||||
lua_pushboolean(L, false);
|
||||
}
|
||||
lua_setfield(L, -2, "hb");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
|
|
@ -42,6 +44,13 @@ int main(int argc, char** argv) {
|
|||
char* mainFile = "main.lua";
|
||||
#endif
|
||||
|
||||
// Change root dir
|
||||
#ifdef ROOT
|
||||
if(chdir(ROOT)) {
|
||||
error(strerror(errno));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Init Lua
|
||||
lua_State *L = luaL_newstate();
|
||||
if (L == NULL) {
|
||||
|
|
|
|||
|
|
@ -306,14 +306,9 @@ void load_thread_lib(lua_State *L) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Pool lib for accessing the pool from the thread //
|
||||
// Libception //
|
||||
// Documentation is in thread.pool.doc.c, because LDoc //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/***
|
||||
The `pool` module. Only accessible from a sub-thread.
|
||||
@module ctr.thread.pool
|
||||
@usage local pool = require("ctr.thread.pool")
|
||||
*/
|
||||
|
||||
static int pool_set(lua_State *L) {
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, "LThreadSelf");
|
||||
thread_userdata* thread = (thread_userdata*)lua_tointeger(L, -1);
|
||||
|
|
|
|||
21
source/thread.pool.h
Normal file
21
source/thread.pool.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// This is a documentation file, not a header. But LDoc.
|
||||
|
||||
/***
|
||||
The `thread.pool` module. Only accessible from a sub-thread.
|
||||
@module ctr.thread.pool
|
||||
@usage local pool = require("ctr.thread.pool")
|
||||
*/
|
||||
|
||||
/***
|
||||
Set a value in the thread's pool.
|
||||
@function set
|
||||
@tparam integer index
|
||||
@param value anything but a table/userdata
|
||||
*/
|
||||
|
||||
/***
|
||||
Get a value from the thread's pool.
|
||||
@function get
|
||||
@tparam integer index
|
||||
@return the value stored
|
||||
*/
|
||||
15
source/uds.c
15
source/uds.c
|
|
@ -16,6 +16,8 @@ The default wlancommID is 0x637472c2.
|
|||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
#define DEFAULT_WLANCOMMID 0x637472c2
|
||||
|
||||
bool initStateUDS = false;
|
||||
|
||||
udsBindContext bind = {0};
|
||||
|
|
@ -73,11 +75,16 @@ Scan for network beacons.
|
|||
static int uds_scan(lua_State *L) {
|
||||
static const size_t tmpbuffSize = 0x4000;
|
||||
u32* tmpbuff = malloc(tmpbuffSize);
|
||||
if (tmpbuff == NULL) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, "Failed to allocated beacon data buffer");
|
||||
return 2;
|
||||
}
|
||||
|
||||
udsNetworkScanInfo* networks = NULL;
|
||||
size_t totalNetworks = 0;
|
||||
|
||||
u32 wlanCommID = luaL_optinteger(L, 1, 0x637472c2);
|
||||
u32 wlanCommID = luaL_optinteger(L, 1, DEFAULT_WLANCOMMID);
|
||||
u8 id8 = luaL_optinteger(L, 2, 0);
|
||||
|
||||
// MAC address conversion
|
||||
|
|
@ -117,7 +124,7 @@ static int uds_scan(lua_State *L) {
|
|||
udsNetworkScanInfo* beacon = lua_newuserdata(L, sizeof(udsNetworkScanInfo));
|
||||
luaL_getmetatable(L, "LUDSBeaconScan");
|
||||
lua_setmetatable(L, -2);
|
||||
memcpy(beacon, &networks[0], sizeof(udsNetworkScanInfo));
|
||||
memcpy(beacon, &networks[i-1], sizeof(udsNetworkScanInfo));
|
||||
lua_seti(L, -3, i);
|
||||
}
|
||||
free(networks);
|
||||
|
|
@ -294,12 +301,12 @@ static int uds_createNetwork(lua_State *L) {
|
|||
size_t passSize = 0;
|
||||
const char *pass = luaL_optlstring(L, 1, "", &passSize);
|
||||
u8 maxNodes = luaL_optinteger(L, 2, UDS_MAXNODES);
|
||||
u32 commID = luaL_optinteger(L, 3, 0x637472c2);
|
||||
u32 commID = luaL_optinteger(L, 3, DEFAULT_WLANCOMMID);
|
||||
u32 recvBuffSize = luaL_optinteger(L, 4, UDS_DEFAULT_RECVBUFSIZE);
|
||||
u8 dataChannel = luaL_optinteger(L, 5, 1);
|
||||
|
||||
udsGenerateDefaultNetworkStruct(&network, commID, dataChannel, maxNodes);
|
||||
Result ret = udsCreateNetwork(&network, pass, passSize, &bind, dataChannel, recvBuffSize);
|
||||
Result ret = udsCreateNetwork(&network, pass, passSize+1, &bind, dataChannel, recvBuffSize);
|
||||
if (R_FAILED(ret)) {
|
||||
lua_pushboolean(L, false);
|
||||
lua_pushinteger(L, ret);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue