int main(int argc, char ** argv) { lua_State * L = luaL_newstate(); //create a plain lua state luaL_openlibs(L); //initialize its libraries //initialize the terra state in lua terra_init(L); // we can execute terra scripts from within the C program now // First, let's extend the terrapath const char *pathextend = "package.terrapath = package.terrapath.." // extend the path so that we can run both in the example directory "';../release/?.t'.." // and in the directory one up which tests are run from "';release/?.t'"; if(terra_dostring(L, pathextend)) { printf("pathextend failed\n"); fprintf(stderr, "%s\n", lua_tostring(L, -1)); lua_pop(L, 1); // pop error message from the stack lua_close(L); return 1; } // then, we can go ahead and execute the hello42 program const char *scriptstring = "import 'typelang.typelang'\n" "\n" "typel hello42() return 21 + 21 end\n" "\n" "print(hello42())\n" "assert(hello42() == 42)\n" "\n"; if(terra_dostring(L, scriptstring)) { printf("script failed\n"); fprintf(stderr, "%s\n", lua_tostring(L, -1)); lua_pop(L, 1); // pop error message from the stack } // finally, let's check to make sure that error reporting // is working ok const char *errscript = "error('causing an intentional error')"; if(terra_dostring(L, errscript)) { fprintf(stderr, "%s\n", lua_tostring(L, -1)); lua_pop(L, 1); // pop error message from the stack } lua_close(L); return 0; }
void setupebb(lua_State * L, ebb_Options * ebboptions) { char * bindir = getexec_dirpath(); if(!bindir) { errquit(L, "ERROR: Failed to retreive path to this executable.\n"); } char buffer[MAX_PATH_LEN]; // plenty of room size_t bufsize = MAX_PATH_LEN; // Make sure we can find the Terra files snprintf(buffer, bufsize, "package.terrapath = package.terrapath..';%s/../include/?.t;'", bindir); if (terra_dostring(L, buffer)) doerror(L); if (ebboptions->uselegion) { // extend the Terra include path snprintf(buffer, bufsize, "terralib.includepath = terralib.includepath.." "';%s/../legion/runtime;" "%s/../legion/runtime/legion;" "%s/../legion/runtime/mappers;" "%s/../mappers;" "%s/../legion_utils;" "%s/../legion/bindings/terra'", bindir, bindir, bindir, bindir, bindir, bindir); if (terra_dostring(L, buffer)) doerror(L); // extend the Lua include path //snprintf(buffer, bufsize, // "package.path = package.path.." // "';%s/../legion/bindings/terra/?.t'", // bindir); //if (terra_dostring(L, buffer)) // doerror(L); // Link the Legion Shared Library into Terra if (ebboptions->debug) { snprintf(buffer, bufsize,"terralib.linklibrary(" "'%s/../legion/bindings/terra/liblegion_terra_debug.so')", bindir); if (terra_dostring(L, buffer)) doerror(L); snprintf(buffer, bufsize,"terralib.linklibrary(" "'%s/../mappers/libmapper_debug.so')", bindir); if (terra_dostring(L, buffer)) doerror(L); snprintf(buffer, bufsize,"terralib.linklibrary(" "'%s/../legion_utils/liblegion_utils_debug.so')", bindir); if (terra_dostring(L, buffer)) doerror(L); } else { snprintf(buffer, bufsize,"terralib.linklibrary(" "'%s/../legion/bindings/terra/liblegion_terra_release.so')", bindir); if (terra_dostring(L, buffer)) doerror(L); snprintf(buffer, bufsize,"terralib.linklibrary(" "'%s/../mappers/libmapper_release.so')", bindir); if (terra_dostring(L, buffer)) doerror(L); snprintf(buffer, bufsize,"terralib.linklibrary(" "'%s/../legion_utils/liblegion_utils_release.so')", bindir); if (terra_dostring(L, buffer)) doerror(L); } if (ebboptions->legionspy) { lua_pushboolean(L, true); lua_setglobal(L, "EBB_LEGION_USE_SPY"); } if (ebboptions->legionprof) { lua_pushboolean(L, true); lua_setglobal(L, "EBB_LEGION_USE_PROF"); } if (ebboptions->partition) { lua_pushboolean(L, true); lua_setglobal(L, "EBB_PARTITION"); } } if (ebboptions->usegpu) { lua_pushboolean(L, true); lua_setglobal(L, "EBB_USE_GPU_SIGNAL"); } if (strcmp(ebboptions->additional, "")) { lua_pushstring(L, ebboptions->additional); lua_setglobal(L, "EBB_ADDITIONAL_ARGS"); } }