Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4962

General • Re: PT52-Lua The Modern Retro computer

$
0
0
So how it works with scripts if you set the system bit ie the execution bit the the script will run straight from the shell. you can do this with attrib from the shell so for example you have a script named prime you could do this

Code:

C:/> attrib prime +xC:/> prime2357
OR you can run any script with a ! (just remember '!' goes before the path)

Code:

C:/> !prime2357
You might want to use pt_malloc but a better choice is lua_newuserdatauv
void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue);
This function creates and pushes on the stack a new full userdata, with nuvalue associated Lua values, called user values, plus an associated block of raw memory with size bytes. (The user values can be set and read with the functions lua_setiuservalue and lua_getiuservalue.)

The function returns the address of the block of memory. Lua ensures that this address is valid as long as the corresponding userdata is alive (see §2.5). Moreover, if the userdata is marked for finalization (see §2.5.3), its address is valid at least until the call to its finalizer.
If you really want to use pt_malloc the header pt52io.h has all you need. I think actual header for it is pt_mem.h

OLED Library you need SSD1306 by Larry Bank from 1/15/2017

Code:

#define loledlib_c#define LUA_LIB#include "lua.h"#include "lauxlib.h"#include "lualib.h"#include <system/node_sys.h>#include <SSD1306/ssd1306.h>/*Driver IC: SSD1306Size: 0.91 inch OLEDResolution: 128 x 32 [ 16 x 4 ] @ 8x8Address: 0x3c; it can also be 0x3d*/static int  oled_init(lua_State *L){    lua_pushinteger(L,oledInit(        luaL_optinteger(L,1,1) & 1,        luaL_optinteger(L,2,0x3c),        OLED_128x32,        luaL_optinteger(L,3,0) & 1,        luaL_optinteger(L,4,0) & 1        )    );    return 1;}static int  oled_shutdown(lua_State *L){    oledShutdown();    return 0;}static int  oled_fill(lua_State *L){    lua_pushinteger(L, oledFill(luaL_optinteger(L,1,0) & 0xff));    return 1;}static int  oled_pixel(lua_State *L){    lua_pushinteger(L, oledSetPixel(        (luaL_optinteger(L,1,0) & 127),        (luaL_optinteger(L,2,0) & 63),        (luaL_optinteger(L,3,0) & 1)        )    );    return 1;}static int  oled_contrast(lua_State *L){    lua_pushinteger(L, oledSetContrast(luaL_optinteger(L,1,0) & 0xff));    return 1;}static int  oled_print(lua_State *L){    lua_pushinteger(L, oledWriteString(        (luaL_optinteger(L,1,0) & 127),        (luaL_optinteger(L,2,0) & 7),        (char*)luaL_optstring(L,3,""),        (luaL_optinteger(L,4,1))        )    );    return 1;}static const luaL_Reg loledlib[] = {    {"init",    oled_init},    {"shutdown",oled_shutdown},    {"fill",    oled_fill},    {"draw",    oled_pixel},    {"contrast",oled_contrast},    {"print",   oled_print},    {NULL,      NULL}};/* }====================================================== */LUAMOD_API int luaopen_oled (lua_State *L) {    luaL_newlib(L, loledlib);    return 1;}
I don't think you can you the returned address for anything. it's handy to know if it's a Flash or ROM location but nothing more that I'm aware of. You can do the same with print for example without the brackets it returns the functions location 0x100#### something because it's in flash.

Statistics: Posted by DarkElvenAngel — Fri Jan 24, 2025 11:01 pm



Viewing all articles
Browse latest Browse all 4962

Trending Articles