Compare commits
2 Commits
bf3eb50b55
...
f365cff590
Author | SHA1 | Date | |
---|---|---|---|
|
f365cff590 | ||
|
77ff5c7f25 |
@ -7,8 +7,6 @@
|
||||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
#include <malloc.h>
|
||||
|
||||
|
||||
/* generated by bindgen.py */
|
||||
void bindgen_load_twn(lua_State *L);
|
||||
@ -18,10 +16,11 @@ void bindgen_upload_context(lua_State *L);
|
||||
|
||||
|
||||
/* 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) {
|
||||
const char *name = luaL_checkstring(L, 1);
|
||||
char *final_path = NULL;
|
||||
SDL_asprintf(&final_path, "%s.lua", name);
|
||||
SDL_asprintf(&final_path, "/scripts/%s.lua", name);
|
||||
|
||||
if (!file_exists(final_path)) {
|
||||
char *error_message = NULL;
|
||||
@ -37,6 +36,7 @@ static int physfs_loader(lua_State *L) {
|
||||
int64_t buf_size = file_to_bytes(final_path, &buf);
|
||||
free(final_path);
|
||||
|
||||
/* TODO: use reader interface for streaming instead */
|
||||
luaL_loadbuffer(L, (char *)buf, buf_size, name);
|
||||
free(buf);
|
||||
|
||||
@ -141,6 +141,7 @@ void game_tick(void) {
|
||||
/* now finally get to running the code */
|
||||
unsigned char *game_buf = NULL;
|
||||
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 (lua_pcall(state->L, 0, 0, 0) != LUA_OK) {
|
||||
log_critical("%s", lua_tostring(state->L, -1));
|
||||
|
Loading…
Reference in New Issue
Block a user