Example lua run string function returns NULL on success and error string on error
| 49 | // Example lua run string function |
| 50 | // returns NULL on success and error string on error |
| 51 | const char * RunString( |
| 52 | #if LUA_BINDINGS_LOCAL_STATE |
| 53 | lua_State* lState, |
| 54 | #endif |
| 55 | const char* szLua) { |
| 56 | if (!lState) { |
| 57 | fprintf(stderr, "You didn't pass a valid lState, either assign that or refactor LoadImguiBindings and RunString\n"); |
| 58 | } |
| 59 | |
| 60 | int iStatus = luaL_loadstring(lState, szLua); |
| 61 | if(iStatus) { |
| 62 | return lua_tostring(lState, -1); |
| 63 | //fprintf(stderr, "Lua syntax error: %s\n", lua_tostring(lState, -1)); |
| 64 | //return; |
| 65 | } |
| 66 | #ifdef ENABLE_IM_LUA_END_STACK |
| 67 | endStack.clear(); |
| 68 | #endif |
| 69 | iStatus = lua_pcall( lState, 0, 0, 0 ); |
| 70 | |
| 71 | #ifdef ENABLE_IM_LUA_END_STACK |
| 72 | bool wasEmpty = endStack.empty(); |
| 73 | while(!endStack.empty()) { |
| 74 | ImEndStack(endStack.back()); |
| 75 | endStack.pop_back(); |
| 76 | } |
| 77 | |
| 78 | #endif |
| 79 | if( iStatus ) |
| 80 | { |
| 81 | return lua_tostring(lState, -1); |
| 82 | //fprintf(stderr, "Error: %s\n", lua_tostring( lState, -1 )); |
| 83 | //return; |
| 84 | } |
| 85 | #ifdef ENABLE_IM_LUA_END_STACK |
| 86 | else if (!wasEmpty) { |
| 87 | return "Script didn't clean up ImGui stack properly"; |
| 88 | } |
| 89 | #endif |
| 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | #define IMGUI_FUNCTION_DRAW_LIST(name) \ |