mchlmmc / CirnOS

Bringing the workflow of Arduino to the Raspberry Pi
GNU General Public License v3.0
101 stars 6 forks source link

Did the following... #11

Closed tilkinsc closed 5 years ago

tilkinsc commented 5 years ago

The source supplied in this pull request are modifications from my LuaConsole source code found at https://github.com/tilkinsc/LuaConsole, which are copyrighted under MIT found at https://github.com/tilkinsc/LuaConsole/blob/master/LICENSE. However, only the supplied modified functions found in this pull request I declare as PUBLIC DOMAIN in the stead of being LuaConsole MIT. Please retain author comments.

This pull request has not been fully tested for syntax errors, and not for run-time errors.

mchlmmc commented 5 years ago

I will test this on my rPi sometime today. The changes to main.c seem good, and should make a more straightforward boot process.

However, I am unsure about changing main.lua. Your example is just a good as mine, but I don't think it's worth changing on its own.

Would you be ok with me making a CirnOS Examples repository that we can drop all our examples into?

mchlmmc commented 5 years ago

Currently this code cannot be compiled, giving me tons of errors. I will try to make it work once I am done working on my current demo, but you could look into it in the meantime.

The errors are as follows:

In file included from SRC/main.c:17: SRC/main.c: In function 'l_print_error': /usr/lib/arm-none-eabi/include/stdio.h:149:23: warning: passing argument 1 of 'printf' from incompatible pointer type [-Wincompatible-pointer-types] #define stderr (_REENT->_stderr) ~~~~~~~^~~~~~~~~~ SRC/main.c:179:10: note: in expansion of macro 'stderr' printf(stderr, " (Runtime) | Stack Top: %zu | %s%s\n", top, msg, type); ^~~~~~ In file included from /usr/lib/arm-none-eabi/include/stdio.h:29, from SRC/main.c:17: /usr/lib/arm-none-eabi/include/stdio.h:187:21: note: expected 'const char * restrict' but argument is of type '__FILE *' {aka 'struct __sFILE *'} int _EXFUN(printf, (const char *__restrict, ...) /usr/lib/arm-none-eabi/include/_ansi.h:65:35: note: in definition of macro '_EXFUN' #define _EXFUN(name, proto) name proto ^~~~~ In file included from SRC/main.c:17: /usr/lib/arm-none-eabi/include/stdio.h:149:23: warning: passing argument 1 of 'printf' from incompatible pointer type [-Wincompatible-pointer-types] #define stderr (_REENT->_stderr) ~~~~~~~^~~~~~~~~~ SRC/main.c:180:10: note: in expansion of macro 'stderr' printf(stderr, "%s\n", tb); ^~~~~~ In file included from /usr/lib/arm-none-eabi/include/stdio.h:29, from SRC/main.c:17: /usr/lib/arm-none-eabi/include/stdio.h:187:21: note: expected 'const char * restrict' but argument is of type '__FILE *' {aka 'struct __sFILE *'} int _EXFUN(printf, (const char *__restrict, ...) /usr/lib/arm-none-eabi/include/_ansi.h:65:35: note: in definition of macro '_EXFUN' #define _EXFUN(name, proto) name proto ^~~~~ In file included from SRC/main.c:17: SRC/main.c: In function 'print_error': /usr/lib/arm-none-eabi/include/stdio.h:149:23: warning: passing argument 1 of 'printf' from incompatible pointer type [-Wincompatible-pointer-types] #define stderr (_REENT->_stderr) ~~~~~~~^~~~~~~~~~ SRC/main.c:215:12: note: in expansion of macro 'stderr' printf(stderr, " (Syntax)"); ^~~~~~ In file included from /usr/lib/arm-none-eabi/include/stdio.h:29, from SRC/main.c:17: /usr/lib/arm-none-eabi/include/stdio.h:187:21: note: expected 'const char * restrict' but argument is of type '__FILE *' {aka 'struct __sFILE *'} int _EXFUN(printf, (const char *__restrict, ...) /usr/lib/arm-none-eabi/include/_ansi.h:65:35: note: in definition of macro '_EXFUN' #define _EXFUN(name, proto) name proto ^~~~~ SRC/main.c: In function 'notmain': SRC/main.c:291:9: error: void value not ignored as it ought to be while(bcm2835_delay((uint32_t) 1000)); ^~~~~~~~~~~~~

tilkinsc commented 5 years ago

Oops I forgot to remove stderr and stdout because it originally used fprintf lol

tilkinsc commented 5 years ago

All fixed.

mchlmmc commented 5 years ago

There's more to it yet, compiling the code yields the following errors: In file included from SRC/LUA/luajit.h:31, from SRC/luabcm.h:17, from SRC/main.c:22: SRC/main.c: In function 'error_test_meta': SRC/main.c:143:22: error: 'L' undeclared (first use in this function) msg = lua_tostring(L, -1); // attempt tostring ^ SRC/LUA/lua.h:279:41: note: in definition of macro 'lua_tostring' #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) ^ SRC/main.c:143:22: note: each undeclared identifier is reported only once for each function it appears in msg = lua_tostring(L, -1); // attempt tostring ^ SRC/LUA/lua.h:279:41: note: in definition of macro 'lua_tostring' #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) ^ SRC/main.c: In function 'print_error': SRC/main.c:220:20: error: 'L' undeclared (first use in this function) top = lua_gettop(L);

Introducing a global lua_State *L fixes this, however I am not sure if that was your intention for these fixes.

Further, once compilation is achieved by adding the L variable CirnOS gives the following error on startup: Error creating Lua state: Success

This can be fixed by changing if ((L = luaL_newstate()) != 0) to if((L = luaL_newstate()) == NULL) See http://pgl.yoyo.org/luai/i/luaL_newstate

Getting past this point gives a new error: PANIC: unprotected error in call to Lua API (no calling environment)

That's as far as I've gotten right now.

What model of rPi do you own? I just got my hands on a model 3, so I should be able to port CirnOS very soon. If so, that should allow you to test this.

tilkinsc commented 5 years ago

Model 3b+, I didn't get to compile it so those errors exist :)

Your are right in every change, and the lua_State* in LuaConsole is pretty much global. To fix not having it global, which is really not trivial to fix nor of use to anybody, is to have the functions that needed said L to get said L via passing it through print_error and error_test_meta.

This unprotected error is because I forgot that you can't call luaopen_* outside of lua, aka it must be pcall()'d off the stack. http://lua-users.org/lists/lua-l/2007-04/msg00383.html

tilkinsc commented 5 years ago

This commit should fix all 3 errors, and I didn't make lua_State* global. Once this is merged I have changes to the program which bounces off these and will start a new pull request.

mchlmmc commented 5 years ago

Works on my Pi Zero. Merged