Example lua run string function returns NULL on success and error string on error
| 41 | // Example lua run string function |
| 42 | // returns NULL on success and error string on error |
| 43 | const char * RunString(const char* szLua) { |
| 44 | if (!lState) { |
| 45 | fprintf(stderr, "You didn't assign the global lState, either assign that or refactor LoadImguiBindings and RunString\n"); |
| 46 | } |
| 47 | |
| 48 | int iStatus = luaL_loadstring(lState, szLua); |
| 49 | if(iStatus) { |
| 50 | return lua_tostring(lState, -1); |
| 51 | //fprintf(stderr, "Lua syntax error: %s\n", lua_tostring(lState, -1)); |
| 52 | //return; |
| 53 | } |
| 54 | #ifdef ENABLE_IM_LUA_END_STACK |
| 55 | endStack.clear(); |
| 56 | #endif |
| 57 | iStatus = lua_pcall( lState, 0, 0, 0 ); |
| 58 | |
| 59 | #ifdef ENABLE_IM_LUA_END_STACK |
| 60 | bool wasEmpty = endStack.empty(); |
| 61 | while(!endStack.empty()) { |
| 62 | ImEndStack(endStack.back()); |
| 63 | endStack.pop_back(); |
| 64 | } |
| 65 | |
| 66 | #endif |
| 67 | if( iStatus ) |
| 68 | { |
| 69 | return lua_tostring(lState, -1); |
| 70 | //fprintf(stderr, "Error: %s\n", lua_tostring( lState, -1 )); |
| 71 | //return; |
| 72 | } |
| 73 | #ifdef ENABLE_IM_LUA_END_STACK |
| 74 | else if (!wasEmpty) { |
| 75 | return "Script didn't clean up imgui stack properly"; |
| 76 | } |
| 77 | #endif |
| 78 | return NULL; |
| 79 | } |
| 80 | |
| 81 | |
| 82 | #define IMGUI_FUNCTION_DRAW_LIST(name) \ |
nothing calls this directly
no outgoing calls
no test coverage detected