Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LuaState.hpp
- #ifdef __cplusplus
- #include <lua5.2/lua.hpp>
- #include <cassert>
- extern "C" {
- #include <physfs.h>
- }
- #else
- #include <lua5.2/lua.h>
- #include <lua5.2/lualib.h>
- #include <lua5.2/lauxlib.h>
- #include <assert.h>
- #include <physfs.h>
- #endif
- typedef int (*lua_CFunction) (lua_State *L);
- lua_State *L;
- int physfs_LuaDofile();
- // LuaState.cpp
- #include "luastate.hpp"
- #include <cstdlib>
- int physfs_LuaLoad()
- {
- int n = lua_gettop(L);
- string filename = (string)lua_tostring(L,-1);
- char* buf;
- PHYSFS_file* myfile;
- assert((myfile = PHYSFS_openRead(filename.c_str())));
- PHYSFS_sint64 length = PHYSFS_fileLength(myfile);
- buf = (char*)malloc(sizeof(char)*length);
- PHYSFS_read (myfile, buf, 1, length);
- PHYSFS_close(myfile);
- lua_pushlstring(L, buf, length);
- free(buf);
- return 1;
- }
- // Main.cpp
- #include "luastate.hpp"
- int main()
- {
- L = luaL_newstate();
- luaL_openlibs(L);
- lua_register(L, "PHYSFS_LoadFile", physfs_LuaLoad);
- lua_close(L);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement