Compare commits

..

No commits in common. "f365cff59072c71072f3a16d576e21c7986fcd5b" and "bf3eb50b55f61140d4614b16d70bcc57755b9d64" have entirely different histories.

View File

@ -7,6 +7,8 @@
#include <lualib.h> #include <lualib.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <malloc.h>
/* generated by bindgen.py */ /* generated by bindgen.py */
void bindgen_load_twn(lua_State *L); void bindgen_load_twn(lua_State *L);
@ -16,11 +18,10 @@ void bindgen_upload_context(lua_State *L);
/* require will go through physicsfs exclusively so that scripts can be in the data dir */ /* require will go through physicsfs exclusively so that scripts can be in the data dir */
/* TODO: allow for bytecode files */
static int physfs_loader(lua_State *L) { static int physfs_loader(lua_State *L) {
const char *name = luaL_checkstring(L, 1); const char *name = luaL_checkstring(L, 1);
char *final_path = NULL; char *final_path = NULL;
SDL_asprintf(&final_path, "/scripts/%s.lua", name); SDL_asprintf(&final_path, "%s.lua", name);
if (!file_exists(final_path)) { if (!file_exists(final_path)) {
char *error_message = NULL; char *error_message = NULL;
@ -36,7 +37,6 @@ static int physfs_loader(lua_State *L) {
int64_t buf_size = file_to_bytes(final_path, &buf); int64_t buf_size = file_to_bytes(final_path, &buf);
free(final_path); free(final_path);
/* TODO: use reader interface for streaming instead */
luaL_loadbuffer(L, (char *)buf, buf_size, name); luaL_loadbuffer(L, (char *)buf, buf_size, name);
free(buf); free(buf);
@ -141,7 +141,6 @@ void game_tick(void) {
/* now finally get to running the code */ /* now finally get to running the code */
unsigned char *game_buf = NULL; unsigned char *game_buf = NULL;
size_t game_buf_size = file_to_bytes("/scripts/game.lua", &game_buf); size_t game_buf_size = file_to_bytes("/scripts/game.lua", &game_buf);
/* TODO: use reader interface for streaming instead */
if (luaL_loadbuffer(state->L, (char *)game_buf, game_buf_size, "game.lua") == LUA_OK) { if (luaL_loadbuffer(state->L, (char *)game_buf, game_buf_size, "game.lua") == LUA_OK) {
if (lua_pcall(state->L, 0, 0, 0) != LUA_OK) { if (lua_pcall(state->L, 0, 0, 0) != LUA_OK) {
log_critical("%s", lua_tostring(state->L, -1)); log_critical("%s", lua_tostring(state->L, -1));